Button issue

Below code I have run this but it’s not working properly.

if st.markdown(btn,unsafe_allow_html=True):
    st.write('Please Help')
    if st.markdown(btn_2,unsafe_allow_html=True):
        st.write('Please help')

I’m using bootstrap to render this button but before performing action it’s showing the text ‘Please help’.

Hello @Daniyal56,

While you can render HTML/JS code through st.markdown, you won’t be able to capture JS callbacks like “button clicked” back into a Python variable.

st.markdown only displays things, hence if st.markdown will always pass and so st.write will always be displayed, so it works as intended.

If you need to build a custom Bootstrap button which responds to click callbacks, you’ll need to build your own Streamlit+Bootstrap button component: this tutorial make for a good starting point https://docs.streamlit.io/en/stable/streamlit_components.html.

Best,
Fanilo

Hello @andfanilo I have used components.html, but still getting the same issue.

components.html is alas only for rendering too, unfortunately you won’t get JS callbacks back to Python variables with it. You need to go through the full bidirectional route, so you can return a boolean from JS when the button is clicked.

Fanilo