9

Hi I am developing a bokeh application to perform some analysis. I want to get the URL parameters from the server so I can decide which data to render in the application.

Currently I can route URLs like http://127.0.0.1:5006/bokeh/videos/?hello=1 with the following configuration, but is there a way I can get the GET parameters {'hello':'1'} from the application?

@bokeh_app.route("/bokeh/analysis/")
@object_page("analysis")
def make_analysis():
    app = AnalysisApp.create()
    return app
chtlp
  • 645
  • 1
  • 6
  • 16

2 Answers2

17

Easier way: a dict of (param name, value) is available in curdoc().session_context.request.arguments.

For your URL http://127.0.0.1:5006/bokeh/videos/?hello=1, it would give {'hello', '1'}.

Emmanuel
  • 13,935
  • 12
  • 50
  • 72
  • 1
    See for example: https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#accessing-the-http-request – Carmellose Nov 17 '17 at 09:41
  • I think this is better answer than getting flask involved. – Lyle Dec 26 '18 at 01:43
  • 2
    `from bokeh.plotting import curdoc` – congusbongus Dec 02 '19 at 02:44
  • How do we deploy so that URL contains the extra ?hello=1 bit. Using bokeh serve my URL address is hostname:port/my_app.py. How do I change this? – A.DS Dec 23 '19 at 16:04
  • @A.DS: you deploy sour SERVER with host and port, not with extra routes or parameters that are hit by your CLIENTS. – Emmanuel Dec 23 '19 at 16:16
  • I used just the hostname and port. when accessing it automatically opens at hostname:port/my_app.py. But when adding the extra bit hostname:port/my_app.py/hello=1, it throws 404 error. – A.DS Dec 23 '19 at 16:51
  • Beware, port/my_app.py/hello=1 is not the same as port/my_app.py/?hello=1 (note the question mark for GET parameters) – Emmanuel Dec 23 '19 at 17:04
2

For Flask (which Bokeh server is built on), you'd access url parameters using:

from flask import request

@bokeh_app.route("/bokeh/analysis/")
@object_page("analysis")
    def make_analysis():
    args = request.args
    app = AnalysisApp.create()
    return app

(the request object gets added to the function scope by the app.route decorator)

Luke Canavan
  • 2,107
  • 12
  • 13