Add cancel button to close modal

Hello group,

I have added a dialog to the app and I’m trying to add cancel button to close the dialog. Below is the code for it but clicking cancel button does nothing. What am I missing here?

I read on the discussions that just calling st.rerun() within the button will close the dialog but it doesn’t works for me.

Thanks for your help with this.

@st.dialog("Confirm Delete")
                def confirm(collection):
                    st.markdown(f"""Confirm deletion of :red[{collection}] collection? 
                                <p>:red[WARNING]: This will also delete all files in this collection.</p>
                                <p>:red[Press esc to cancel]
                                """, 
                                unsafe_allow_html=True
                                )
                    leftcol, rightcol = st.columns(2)
                    with leftcol:
                        if st.button("Delete",use_container_width=True):
                            chroma_db.delete_collection(name=collection)
                            st.rerun()
                    with rightcol:
                        if st.button("Cancel",use_container_width=True):
                            st.rerun()