deephaven / streamlit-deephaven

Deephaven Streamlit custom component
MIT License
1 stars 3 forks source link

Specifying object_id= for display_dh() results in widgets that do not update #10

Closed niloc132 closed 3 months ago

niloc132 commented 4 months ago

When calling display_dh with object_id= set, each time streamlit re-runs the script the widget instances are correctly updated when used from the web IDE, but the iframe visible in the streamlit UI does not update.

Steps to reproduce

Run some code that calls display_db with object_id set, and either use the "re-run" command (whether or not the code is changed), or manipulate some UI component to cause the script to re-run automatically. For example

seconds = st.selectbox("Seconds", [1, 2, 3], index=1)

# create a DH table and a DH figure
from deephaven import time_table, ring_table
from deephaven.plot.figure import Figure

t = time_table(f"PT{seconds}S").update([f"x={seconds}"])
display_dh(t, height=200, object_id="t")

In this case, when the dropdown changes (or when re-run is clicked, etc), the visible table should restart with a different interval between rows.

Actual behavior: no amount of changes or re-running the script causes the table to have a different interval between rows in the time table.

Proposed fix

Add some kind of "cache-busting" query string param to the iframe URL, so that streamlit is forced to change the iframe's src attribute, but only when the actual widget instance changes. For example at https://github.com/deephaven/streamlit-deephaven/blob/4d1bbf41dbb4cfe6cf3337aa0ab14047b00f46fb/streamlit_deephaven/__init__.py#L152

it might have &nonce={id(widget)} added to the end - not used by the server or the app itself, but signaling only to streamlit that the iframe needs to be refreshed.

kzk2000 commented 4 months ago

btw, {_path_for_object(widget)} is redundant at this point and can be simplified to ...iframe/widget/?name=