snehankekre / streamlit-tensorboard

Streamlit component for TensorBoard, TensorFlow's visualization toolkit
https://pypi.org/project/streamlit-tensorboard/
MIT License
38 stars 7 forks source link

Reuse TensorBoard on port {port} (pid {pid}) if opened previously #5

Open snehankekre opened 3 years ago

snehankekre commented 3 years ago

Each widget interaction with Streamlitt causes the script to rerun from top to bottom. This execution model leads to the creation of a new TensorBoard server for every interaction and new connection to the Streamlit app.

Desired behavior:

  1. If a TensorBoard server is running, connect to it instead of opening a new one.
  2. Reuse cached connection for viewers of the app. Do not open a new TensorBoard for each viewer.
snehankekre commented 3 years ago

PR #7 fixed this issue. Closing for now.

snehankekre commented 3 years ago

Reopening as PR #7 only reused the same port. New TensorBoard servers are created with different pid's.

penfever commented 2 years ago

I believe I am encountering an issue related to this problem.

I am connecting multiple Tensorboards to a radio button, allowing the user to choose which results to view. If I do this with the same port reused for all instances, the log directory is also reused (and the Tensorboard does not change).

mod_pick = st.radio(
     "Pick a model",
     ('Densenet: Ground', 'Resnet: Ground', 'Densenet: Aerial'))

if mod_pick == 'Densenet: Ground':
    st.subheader("Densenet: Ground")
    st_tensorboard(logdir="results/tensorboard/densenet", port=6006, width=1080)
elif mod_pick == 'Resnet: Ground':
    st.subheader("Resnet: Ground")
    st_tensorboard(logdir="results/tensorboard/resnet", port=6006, width=1080)
elif mod_pick == "Densenet: Aerial":
    st.subheader("Densenet: Aerial")
    st_tensorboard(logdir="results/tensorboard/densenet_aerial", port=6006, width=1080)

If I open a new port, the behavior is as expected (a new logdir loads in a new Tensorboard)

mod_pick = st.radio(
     "Pick a model",
     ('Densenet: Ground', 'Resnet: Ground', 'Densenet: Aerial'))

if mod_pick == 'Densenet: Ground':
    st.subheader("Densenet: Ground")
    st_tensorboard(logdir="results/tensorboard/densenet", port=6006, width=1080)
elif mod_pick == 'Resnet: Ground':
    st.subheader("Resnet: Ground")
    st_tensorboard(logdir="results/tensorboard/resnet", port=6007, width=1080)
elif mod_pick == "Densenet: Aerial":
    st.subheader("Densenet: Aerial")
    st_tensorboard(logdir="results/tensorboard/densenet_aerial", port=6008, width=1080)