franekp / streamlit-permalink

MIT License
39 stars 2 forks source link

Empty list in query params #8

Closed EPronovost closed 5 months ago

EPronovost commented 6 months ago

Hi! I noticed a bug where streamlit-permalink is unable to distinguish between "the chosen value is an empty list" and "there is no chosen value" for list-based widgets like multiselect. This is fine so long as the default value is also an empty list, but causes issues with a non-empty default value.

For example,

import streamlit as st
import streamlit_permalink as stp

got = stp.multiselect("Multiselect", ["A", "B"], ["A"], url_key="multiselect")
st.write("Got:", got)

I open the app at http://localhost:8501/ and see A selected. If I manually click on B the URL changes to http://localhost:8501/?multiselect=A&multiselect=B as expected. If I reload the page my selections will be preserved.

However, if I then clear the multiselect (such that nothing is selected) the URL goes back to http://localhost:8501/. If I reload the app at this point it'll go back to the default entry ["A"], losing my selection.

I believe we need something like multiselect=_EMPTY_LIST in the query params to address this. I'm happy to contribute the fix for this, and wanted to get your feedback before putting up a PR.

franekp commented 5 months ago

Sounds good!

EPronovost commented 5 months ago

@franekp https://github.com/franekp/streamlit-permalink/pull/9 is ready for your review when you have time, thanks!

franekp commented 5 months ago

Done. New version here: https://pypi.org/project/streamlit-permalink/0.5.2/

EPronovost commented 5 months ago

Thank you!