Hi
Yogesh,
A few clarifications are probably in order. First, it's
probably a good idea to review the user’s guide section on
running a bokeh server:
[http://bokeh.pydata.org/en/latest/docs/user_guide/server.html](http://bokeh.pydata.org/en/latest/docs/user_guide/server.html)
Then, just to make sure expectations are set, it's worth
mentioning: Bokeh apps always run on a Bokeh server itself.
I’m not sure there is any confusion on this point, I just
wanted to make sure. So then, the question becomes: how do I
embed an app running on a Bokeh server in some other webpage
or web app (e.g. a Flask or Django or whatever app). There are
two general approaches:
* use iframes -- this is simple and works perfectly well. This
is how demo.bokehplots.com works for instance
* use autoload_server -- described here: [http://bokeh.pydata.org/en/latest/docs/user_guide/embed.html#server-data](http://bokeh.pydata.org/en/latest/docs/user_guide/embed.html#server-data)
This all assumes you are running the app in the manner:
bokeh serve myapp.py
This is the most recommended way to do things. It is the
easiest to write and deal with. There is another way, using
“bokeh.client” to create sessions “on demand” from e.g. Flask
apps, but this is more complicated, and the main reason that
is was needed at all (individual session customization) can
now be accomplished with HTTP request arguments with the
recommended way I mentioned above. I would not recommend
looking at bokeh.client, push_session, etc. first.
Hope that helps,
Bryan
> On Sep 12, 2016, at 8:44 AM, Yogesh Kulkarni <[email protected] >
wrote:
>
> I wish to build a generic flask based application, which
embeds bokeh plots and widgets. So I was looking out for some
ready samples. Came across the Slider. So was just trying
that.
>
> I did not get the meaning or the relevance of statement
‘bokeh is no longer flask based’. Whatever it is based of, can
I include it in a generic flask based app? or Any other
generic template based web framework?
>
> Any other example, which shows embedding of bokeh plots,
widgets in a generic html template would also do.
>
> Just wish to put forth: I am learning bokeh by doing a
sample app. It will be a dashboard, showing streaming plots,
widgets like drop-downs, pie charts, data tables, links to
other pages,images, etc. I am going step by step. Once this
flask embedding works, then I will try to embed streaming
plots. As a stretch goal, I will be exploring if drill-down
charts can be made. Meaning, you create, say a histogram chart
using ‘group-by’ on certain data and show it. Once you click
on one of the bars, subplot of expanded data appears.
>
>
> On Monday, September 12, 2016 at 6:55:11 PM UTC+5:30,
Sarah Bird wrote:
> Bokeh is now at version 0.12.2. It has undergone major
changes since 0.9 and I wouldn’t recommend running code from
then.
>
> The bokeh server, for example, is no longer based on
flask.
>
> Get a version of the example that matches the version of
bokeh you’re running. e.g. here’s the sliders example for
0.12.2: https://github.com/bokeh/bokeh/blob/0.12.2/examples/app/sliders.py
>
> To switch versions in github, there is a dropdown near
the top of the page - select a release from “tags”
>
> Sincerely,
>
> Sarah Bird
>
>
> On 9/12/16 6:39 AM, Yogesh Kulkarni wrote:
>> I am seeing so many versions of the slider flask app
example, with different html templates, some using session,
some not, some using autoload, some not, etc. Not able to run
anyone which I came across. There are just bits and pieces of
snippets. Also, did not follow the documentation on
embedding. I just want a single definitive source that runs
without any issues.
>>
>> The one that has clean arrangement I saw was at [https://github.com/mbertoll/bokeh_examples/tree/master/sliders](https://github.com/mbertoll/bokeh_examples/tree/master/sliders)
>>
>> Downloaded the source. Built project in PyCharm. But
did not run in the first go (had some errors). Modified to
address the errors, the code looks like below:
>>
>> The SliderApp class:
>>
>> class SliderApp:
>>
>>
>> def __init__(self):
>>
>>
>> # Removed code for just this explanation. it creates
sliders
>>
>>
>>
>> def get_app(self):
>>
>>
>> # Set up layouts and add to document
>> inputs = VBox(children=[self.text,
self.offset, self.amplitude, self.phase, self.freq])
>>
>> hbox
>> = HBox(children=[inputs, self.plot])
>>
>>
>> return
>> hbox
>>
>>
>>
>> The flask script is:
>> app = Flask(__name__)
>>
>>
>>
>> @app.route('/')
>> def index():
>>
>> applet
>> = SliderApp()
>>
>> layout
>> = applet.get_app()
>>
>> curdoc
>> ().add_root(layout)
>>
>> script
>> , div = components(layout)
>>
>>
>> return render_template('slider_app. html',
plot_script=script, plot_div=div )
>>
>>
>>
>>
>> if __name__ == '__main__':
>>
>>
>> print("STARTED")
>>
>> app
>> .run(debug=True)
>>
>> And the slider_app.html is:
>>
>> <!DOCTYPE html>
>> <html lang="en">
>>
>>
>> <head>
>>
>>
>> <meta charset="utf-8">
>>
>>
>> <title>Bokeh Plot</title>
>>
>>
>> <link rel="stylesheet" href="[http://cdn.pydata.org/bokeh/release/bokeh-0.9.1.min.css](http://cdn.pydata.org/bokeh/release/bokeh-0.9.1.min.css) "
type=“text/css” />
>>
>>
>> <script type="text/javascript" src="[http://cdn.pydata.org/bokeh/release/bokeh-0.9.1.min.js](http://cdn.pydata.org/bokeh/release/bokeh-0.9.1.min.js) "></script>
>>
>>
>> </head>
>>
>>
>> <body>
>>
>> {{ plot_div | safe }}
>> {{ plot_script | safe }}
>>
>> </body>
>> </html>
>>
>> Kept 'bokeh serve' running in another window. And
they executed flask script from pycharm.
>>
>> It gave:
>>
>> STARTED
>> * Running on [http://127.0.0.1:5000/](http://127.0.0.1:5000/) (Press CTRL+C to quit)
>> * Restarting with stat
>> STARTED
>> * Debugger is active!
>> * Debugger pin code: 607-949-136
>>
>> Nothing is seen at [http://127.0.0.1:5000/](http://127.0.0.1:5000/)
>>
>> Not sure what I am missing? Please guide.
>>
>>
>> --
>> 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/33b7ba97-e7ca-445e-9a95-1ead1813262c%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/33b7ba97-e7ca-445e-9a95-1ead1813262c%40continuum.io) .
>> For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout) .
>
> --
> Sarah Bird
> Developer, Bokeh
>
>
>
>
> --
> 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/a0fc0448-df7d-4176-86b9-ad5ba4e96699%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/a0fc0448-df7d-4176-86b9-ad5ba4e96699%40continuum.io) .
> For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout) .