Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add song id in url param #8

Closed
slevin48 opened this issue Nov 5, 2022 · 4 comments
Closed

Add song id in url param #8

slevin48 opened this issue Nov 5, 2022 · 4 comments

Comments

@slevin48
Copy link
Owner

slevin48 commented Nov 5, 2022

@slevin48
Copy link
Owner Author

slevin48 commented Nov 5, 2022

Solved here:
https://discuss.streamlit.io/t/how-to-use-dropdown-with-url-query-parameter/13337

import streamlit as st

# callback to update query param on selectbox change
def update_params():
    st.experimental_set_query_params(option=st.session_state.qp)

options = ["cat", "dog", "mouse", "bat", "duck"]

query_params = st.experimental_get_query_params()

# set selectbox value based on query param, or provide a default
ix = 0
if query_params:
    try:
        ix = options.index(query_params['option'][0])
    except ValueError:
        pass

selected_option = st.radio(
    "Param", options, index=ix, key="qp", on_change=update_params
)

# set query param based on selection
st.experimental_set_query_params(option=selected_option)

# display for debugging purposes
st.write('---', st.experimental_get_query_params())

@slevin48
Copy link
Owner Author

slevin48 commented Nov 5, 2022

image

@slevin48
Copy link
Owner Author

slevin48 commented Nov 6, 2022

Solved with session state and callback function
https://blog.streamlit.io/session-state-for-streamlit/

@slevin48
Copy link
Owner Author

slevin48 commented Nov 6, 2022

prototyped in param_app.py

@slevin48 slevin48 closed this as completed Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant