Setting url parameters?

It is documented here how to access the get parameters. Does Bokeh provide any utilities to set the parameters in the url? For example, it could be useful to be able to share a link with a particular configuration of the menu items/selections/zoom level, etc.

I’m pretty optimistic this can be done with .js_on_change + CustomJS, but I wonder if someone has tried this already and has some snippet/advice.

@rsdenijs1 Bokeh doesn’t really have any opinions about creating URLs (because there aren’t really any places where it ever needs to). If you need to construct a URL for a link in a Div (or whatever), that is generally up to you.

It does not need it but it is useful for users. For instance, streamlit added some support for this recently Add st.experimental_(get|set)_query_params capability by zhaoooyue · Pull Request #1169 · streamlit/streamlit · GitHub.

Bokeh is already a very large library. Every amount of extra weight added incurs cost in terms of maintenance, documentation, support. it would be hard to justify this as a priority given that AFAIK there are already existing tools and libraries in both Python and JS that can help with building up URLs, if you want or need them.

Yeah, I don’t think Bokeh needs to support this, because technically it should already be possible to do it. I asked because some other users may have already done this for their projects and may have some useful snippets. For instance, some snippet that can be added to the JS callbacks on Select widgets to auto-update the URL when a new value is selected.

1 Like

The little function in this SO answer is probably the best answer for most cases

Thanks. Yeah that is part of it. I think a full solution for having a sharable link would require

  • On session init, make sure that when accessing the root url, the values the tracked widgets is read and somehow set in the url. It seems that the backend would need to trigger some JS on the frontend. I dont know if there is a hook for that already, but this could possibly be done through changing the state of a dummy widget.
  • If some query args were are already provided in the request, set the widget states accordingly.
  • Add JS callbacks to each of the tracked widgets to update the url, which can be done with a combination of the SO answer posted above + changing the actual url.

@rsdenijs1 when you said “be able to share a link” I thought you meant constructing random, arbitrary URLs. Do you only specifically mean share a link to the app itself? If so, that’s a much narrower question and maybe it might make sense to try and facilitate something. But there would also be questions/concerns about cases with proxies, etc. I am not sure it’s a completely straightforward task.

Oh yeah that was a disconnect then :), I should have been more precise.
The use case I have in mind is user A comes to the dashboard, clicks around, find something interesting and then wants someone else to look at the same thing. They would simply copy paste the url (or click some copy url button), send it over to user B, who can then see the same state.

As you say, it is probably not trivial. It would be interesting to see how this could be done in Bokeh today to see the pain points, and then maybe identify come utilities that could be added to Bokeh to make this easier. I do think it is a pretty common use case though.

Well, generating a “snapshot” URL is a more narrowly scoped ask, so feel free to make a GitHub Issue (I can’t promise any time frame at all for when it might be looked at but at least the idea will be recorded in the best place)

1 Like

Done. For reference: Allow Bokeh to generate a "snapshot" URL · Issue #10994 · bokeh/bokeh · GitHub