☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Add roots to curdoc() dynamically not updating

Community Supportserver
Cosmidark
Cosmidark

I would like to do something similar to this:


def upload_h5_to_server(attr, old, new):
    filename = write_temp_file(file_input.value)
    curdoc().add_root(ExtendedView(sync.Sync(filename)).layout)


file_input = FileInput(align='end', accept='.h5')
file_input.on_change('value', upload_h5_to_server)

curdoc().add_root(file_input)
curdoc().title = "SyncViewer"

Unfortunately, when upload_h5_to_server is called via callback, this update (at least visually) doesn’t occur. If I call it manually, it will update as expected but I assume this is b/c no session has been setup yet.

Is there a proper technique for this?

⌁   Link to post
Bryan
Bryan

@Cosmidark c.f. similar recent post

replace “completely clearing curdoc” with “adding roots dynamically” above.

⌁   Link to post
Cosmidark
Cosmidark

I think that’s literally what my code above is doing. I did try to clean it up a bit with the name property and select function.

I’m not sure why it would be considered unusual to at least add elements dynamically though. In the particular use case I have (that screen show from my prior post), I don’t know how many lines of data are coming in so I can’t pre-generate a set of empty plots.

In my case, I do have a top level layout composed of my plots, some data tables and a few controls. The plots are added once I know how many there should be.

⌁   Link to post
Bryan
Bryan

It is, I was adding context for “I feel like this isn’t really the intent.”

I’m not sure why it would be considered unusual to at least add elements dynamically though.

I’m not sure what to add except to note that in practice, almost no one ever seems to do it, which is also exactly why it is more likely to suffer from bugs. As I mentioned in the other topic, a GH issue with an MRE would be appropriate.

⌁   Link to post

End of archived discussion · Replies are disabled