On Jan 2, 2019, at 15:24, [email protected] wrote:
It works finally! Here is the code snippet for Flask decorator that worked. I got it working after playing around some options presented in:
bokeh.client.session — Bokeh 3.3.2 Documentation
@app.route('/myapp')
@requires_auth
def myapp():
s_id = session_id.generate_session_id()
# Embed bokeh app into HTML via Flask Render
script = server_session(session_id=s_id, url="http://127.0.0.1:5100/myapp"\)
return render_template("myapp.html", script=script, template="Flask")
Now I have to work on checking sessions and authorization. The Flask page is rendering the bokeh app even after logging out. Maybe thats a separate question.
Thanks for all the help.
On Wednesday, January 2, 2019 at 10:07:12 PM UTC, Bryan Van de ven wrote:
Hi,
Not offhand. The signed session capability has not been very much used by anyone, as far as I know. Yours is the first question I can recall seeing about it since it was introduced three years ago. The basic API is very well covered by unit tests but its possible some wider integration bug has been introduced through disuse. To speculate further will require me to actually run code and dig around. As I mentioned I'm happy to do so if you can provide a compete, miminal starting point in a gist or repo.
Thanks,
Bryan
> On Jan 2, 2019, at 13:57, kaushikma...@gmail.com wrote:
>
> OK I tried this, although I am not sure if I did it correctly. And that didn't help either.
>
> Any other suggestion?
>
> @app.route('/myapp')
> @requires_auth
> def myapp():
> s_id = session_id.generate_session_id()
> script = server_document("http://127.0.0.1:5100/myapp",arguments={"bokeh-session-id": s_id })
> return render_template("myapp.html", script = script)
>
>
>
> On Wednesday, January 2, 2019 at 6:15:56 AM UTC, Bryan Van de ven wrote:
> Hrm,
>
> Can you try passing the session ID in the arguments parameter, as I described earlier? Something like:
>
> arguments={ 'bokeh-session-id": s_id }
>
> That should properly add the HTML argument after the autoload.js endpoint.
>
> If that doesn't work I think a minimal reproducer in a GH repo or gist would be needed to investigate further.
>
> Thanks,
>
> Bryan
>
> > On Jan 1, 2019, at 17:59, Bryan Van de ven <[email protected]> wrote:
> >
> > Hi,
> >
> > All the "extra stuff" is added by Bokeh, and is required in order to properly embed a Bokeh app. There is no way to avoid it, unless you want to embed using an IFrame, instead of server_document.
> >
> > In any case, your problem is that you are trying to add "?bokeh-session-id=" yourself, by hand. You should not do this, and do not need to. As you can see in the link that is generated, Bokeh already adds that automatically, as part of the "extra stuff". Just leave that off.
> >
> > If you do need to add your own custom HTML args (you don't here, but just FYI) you must do that by passing a key/value dict for the "arguments" parameter to server_document:
> >
> > https://bokeh.pydata.org/en/latest/docs/reference/embed.html#bokeh.embed.server_document
> >
> > That will ensure that they are formatted correctly.
> >
> > Thanks,
> >
> > Bryan
> >
> >> On Jan 1, 2019, at 10:24, kaushikma...@gmail.com wrote:
> >>
> >> I am pulling all my hair out configuring a flask based site, embedding bokeh apps and imposing a session ID using BOKEH_SECRET_KEY and BOKEH_SIGN_SESSIONS. The signed session IDs work fine when I go straight to the app page server by the bokeh server like so: 127.0.0.1:5100/myapp
> >>
> >> But I am not having much luck with passing the page link along with the signed session id inside a flask template. Let me explain. Below is the decorator in my flask code:
> >>
> >> @app.route('/myapp')
> >> @requires_auth
> >> def myapp():
> >> s_id = session_id.generate_session_id()
> >> #return redirect("http://127.0.0.1:5100/myapp?bokeh-session-id={}“.format(s_id), code=302)
> >> print ("http://127.0.0.1:5100/myapp?bokeh-session-id={}”.format(s_id))
> >> script = server_document("http://127.0.0.1:5100/domeProfile?bokeh-session-id={}".format(s_id))
> >> return render_template("myapp.html", script = script)
> >>
> >> As you can see I am printing the URL that is passed to the flask template, myapp.html for diiagnostics. The URL printed :
> >>
> >> http://127.0.0.1:5100/myapp?bokeh-session-id=LVbPpfnUoBJpC2pWYef5A52LsiZkq2KFriHgoNjOkTly-CoI2IGKIvL7e7ZrIMax5tExlq_wod7wKIAIsdvHIT98
> >>
> >>
> >> is good to go and I can see the link in browser for the app. However the actual flask page at 127.0.0.1:5000/myapp shows the navbar etc, but content is blank where the bokeh app is supposed to load. The intention is for the template to show the bokeh app using {{ script|safe }}. When I check the page source in the rendered page of 127.0.0.1:5000/myapp, I see that the link generated is like this:
> >>
> >> http://127.0.0.1:5100/myapp?bokeh-session-id=LVbPpfnUoBJpC2pWYef5A52LsiZkq2KFriHgoNjOkTly-CoI2IGKIvL7e7ZrIMax5tExlq_wod7wKIAIsdvHIT98/autoload.js?bokeh-autoload-element=1001&bokeh-app-path=/domeProfile&bokeh-absolute-url=http://127.0.0.1:5100/myapp?bokeh-session-id=LVbPpfnUoBJpC2pWYef5A52LsiZkq2KFriHgoNjOkTly-CoI2IGKIvL7e7ZrIMax5tExlq_wod7wKIAIsdvHIT98" id="1001"
> >>
> >>
> >> which explains why the content is blank. What is all the extra stuff being added to the link I am passing? This autoload.js stuff is beyond me. How can I pass the link to the flask template in its pure form and avoid the extra stuff tagged on?
> >>
> >> --
> >> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> >> To post to this group, send email to bo...@continuum.io.
> >> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f2daeba1-17bb-4b05-aa79-6ff723ddda99%40continuum.io\.
> >> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
> >
>
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/815517a0-6a35-4ff4-9d95-c5c90dfae488%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/cad409ff-c431-4c4f-a4d2-029e816cdd11%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.