I am using bokeh to plot my math functions created with python/numpy.
I would like to use sliders as shown in
http://docs.bokeh.org/en/latest/docs/server_gallery/sliders_server.html
Once I create the html file with the plot, I would like to select different values on the sliders which modify the plot and then read back the chosen values in into python to use it for other manipulations.
What is the best way to read the chosen value on the slider from the html file back into python ?
I saw pyquery could be useful, but I cannot really figure that out.
Any suggestions would be appreciated based on above scenario.
There are two slider examples in the bokeh repo, where the slider is connected back to python via the bokeh server.
Sliders App
Taylor server
If this isn't what you were after, can you elaborate a little more?
A static HTML file and the state of the slider is inside a web browser and never reflected back to the HTML file. What you should be doing is to use bokeh-server - answered via bokeh-google group
Related
If an EXCEL chart is pasted into a PowerPoint presentation as an EXCEL object, it is possible to hover the mouse over the line and see it's value. My boss likes this feature. I don't like having to do charts in EXCEL.
It is possible to get the same effect with bokeh or plotly, but as far as I am aware, that either relies on a stand-alone html file or a server instance.
Is it possible to paste a bokeh chart into a PowerPoint presentation preserving the feature that when you hover your mouse over a point, the value (and some other information) pops up?
Or is there another python solution that would allow this feature in PowerPoint (ppt is essential) while also allowing plots to be generated via code?
An available option is to create powerpoints with Plotly: https://towardsdatascience.com/embed-interactive-plots-in-your-slides-with-plotly-fde92a5865a and https://evidencen.com/how-to-embed-plotly-graphs-in-powerpoint/
Also it seems this question has been asked before and you can hyperlink the HTML source in the .pptx file: Output of Plotly in PowerPoint
yes. it's a hover tool. here is an example
I have an interactive graph generated by Plotly in Python that I saved to an html file using plotly.offline.plot(fig, filename='/tmp/interactiveGraph.html')
I am now trying to embed this interactive graph into some kind of webpage, using either Dash or Django. I'm leaning toward Django at the moment, given that I have an html version of the graph. Which would be better?
My code for the webpage is in a separate file from the code where I am creating the graph.
A lot of the tutorials I've found online just say to add a few lines to the template, but I don't know how to get those lines that they've described.
tl;dr: I'm looking for guidance as how to integrate an html file-for a Plotly interactive graph-with a web python script using Django or Dash
Side Question:
what is the difference between
plotly.offline.plot(fig, include_plotlyjs=False, output_type='div')
and what I have above?
Reference:
https://github.com/ricleal/DjangoPlotLy
https://www.pythonsetup.com/how-implement-data-visualization-django-and-plotly/
I would highly reccomend Django, its a great framework. As for this, the best option is to generate the data via JavaScript and Plotly has a great library for this. If you must use python, then Django can be used. Assuming you are familiar with Django, inside of your view you can collect your data and build your graph ( I would reccomend a celery task for something long running like this unless they are small graphs), and you can then collect the return from creating the graph in div format. This will return a string that holds all the needed html and css for the graphs. Put this inside of you get_context_data() method in your view and place it into the dictionary. You can the use that object inside of a template. I have done this before, if you are having a hard time feel free to DM me. Hope this helps some!
In regards to your side question, I believe having False for including JS will make the graph a bit smaller assuming you have an include for the plotly JS library. They might have done this in a newer release to make the graphs faster as they were significantly slower in the browser from python that the JS rendered one.
I'd like to output the image to the web created in matplotlib having the very same functionality like it has on desktop when you run the image.show(), for example scaling, moving along the plot more thoroughly.
I've checked out #stack and got old post only offering static images or gif or matplotlib.animate()
I aslo had a look at matplotlib widgets, but those are for desktop GUI only as far as I can see.
Please share some experience or ideas regarding how can I achieve it.
Thanks
Matplotlib is a server side library so you cannot do anything on the client side like that.
The closest you can come is to either use mpld3 (mpld3 works by converting a matplotlib graph into the html/js that a d3 js graph would need to render) or a different client side library that plots points.
The easiest way of serving pure matplotlib to the web is using a jupyter notebook.
Other than that, you may want to look at specific libraries like Plotly or bokeh.
I am working on generating some plots using python, but I am generating these plots using matplotlib which is saved as images. If I create an html page as a report with these plots, they are static images. I cannot zoom in or roll over on the plot to see more detailed or specific information on a time series plot.
My question is how can I make these plots dynamic? Can someone suggest the best way to get started and move forward from there?
You should use some additional libraries to achive your goal.
For example, there some good Python web frameworks wich you can use:
CherryPy - allows you to simply write web-app with Python and you can import your plot there.
Plotly Python API - it would simply generate interactive plot, but store it at Plotly platform, but they provide embeded-code option, so you can use it on your site.
I would suggest Plotly, because it is much simpler, but it depends on your needs.
You will definitely want to do it using javascript. It's by far your best option when it comes to quickly make interactive graphs that you can present to a lot of users. Any of these js libraries will do a great job.
You will then want python to provide the data. Depending on the js library you are using, you might be able to parse data from .json, .csv, etc...
If you don't need the data that makes up your plots to change (with user input, for example), then generating and saving flat files with python and having javascript parsing them from some directory might be just enough.
Otherwise, you want to take a look at a python web framework and use one as backend to serve the plots data by request (in that case .json is probably the right format).
Frameworks like Flask, CherryPy, Pyramid or even web2py might be the easier ones to start with.
I have a project with many scripts using Matplotlib. I'd like to build a web interface for this project.
How do you place a Bokeh chart within a Chameleon template? I'm using Pyramid and the Deform bootstrap if that matters.
Does anyone have a good example out there?
There are several different issues to address here.
If you are truly trying to port a lot of Matplotlib plots into interactive JS, then it's possible that the mpld3 project is a good fit for you. However, you should be aware that by using D3, there will be performance implications, depending on how many points are in your plot. Bokeh also does have basic Matplotlib support now, and will only be getting more. Jake is currently refactoring the mpld3 project into an explicit exporter and then D3 renderer, and we will also be potentially building off of this work for the Bokeh Matplotlib support.
To do this with Bokeh, you can grab the raw HTML for a plot by looking at how e.g. HTMLFileSession.dumps() is implemented: https://github.com/ContinuumIO/bokeh/blob/master/bokeh/session.py#L295. The default template is bokeh/templates/base.html; however, this is a full HTML file, and not a fragment. The dumps() method is pretty straightforward, as is the default template, so you should be able to get what you need from looking at those. Hopefully for the next release, we will have finished out a HTMLFragmentSession which will make it easier to embed.
You want to use plot.create_html_snippet. This function returns the code that you want to appear in the HTML, the function also writes out an embed file.
This is what an embed snippet looks like
<script src="http://localhost:5006/static/dc0c7cfd-e657-4c79-8150-6a66be4dccb8.embed.js" bokeh_plottype="embeddata" bokeh_modelid="dc0c7cfd-e657-4c79-8150-6a66be4dccb8" bokeh_modeltype="Plot" async="true"></script>
the following arguments control how the embed file is written out, and where the js code searches for the embed files.
embed_base_url controls the url path (it can be absolute or relative) that the javascript will search for the embed file in.
embed_save_loc controls the directory that python will write out the embed file in. embed_save_loc isn't necessary when server=True
static_path controls the url path (it can absolute or relative) that the javascript will use to construct URLS for bokeh.js and bokeh.css. It defaults to http://localhost:5006/static/, but could just as easily point to a CDN
When running the bokeh server, navigate to http://localhost:5006/bokeh/generate_embed/static . I think this requires you to be running on master because of a bug.
I hope this helps.