So I've been trying to learn Bokeh recently and everything was going well but suddenly whenever I try and make a Bokeh plot the browser just shows a blank page. I get no error codes just the blank page. This is with programs that I was successfully using to create plots just a couple days ago. I even tried loading a html plot file I'd made a few weeks ago that had worked on co-workers computers and got the same result. I even tried one of the basic example code and got the same blank page.
from bokeh.plotting import figure, output_file, show
p = figure(title="line", plot_width=300, plot_height=300)
p.line(x=[1, 2, 3, 4, 5], y=[6, 7, 2, 4, 5])
show(p)
Never thought to try it but do standard Bokeh plots work if you are not online? Does it callout to an external server to generate the plots and maybe now some IT changes at my work are preventing the plots from being generated?
Thanks for any help!
It does not call out to an external server, but it does require the browser to load a JavaScript library, BokehJS. By default (and by popular demand) BokehJS is loaded remotely from a CDN (specifically, from https://cdn.bokeh.org). Accordingly, viewing a Bokeh plot that is configured to use CDN resource requires an active and working network connection.
But it's possible to use "inline" resources, which means the BokehJS library is included directly in the HTML output that Bokeh (the python library) generates. The easiest way to to do this is to set the environment variable:
BOKEH_RESOURCES=inline
There are other ways to specify resources, though, too. For more details see the documentation.
As an aside, in a situation like this it is helpful to consult your browser's JavaScript console. If the CDN resources can't be loaded, you will see the error there.
Related
I am using Jupyter notebook on my laptop (the version coming with Anaconda) to perform some sensitivity analysis.
I use plotly to display the results and I like the interactive features that it has.
However, when I am trying to display more than 7/8 interactive plots on the same notebook, some plots disappears and the output cells of those plots go crazy (see picture attached).
Issue with plotly
A solution I found was to disable the interactive feature at least for some of the plots, changing the diplay mode in config as:
config = {'staticPlot': True}
fig.show(config=config)
This method works, however, I like the feature and I was wondering if there was a solution that does not imply disabling the interactive view.
I read about this post where they say it might be a memory issue (even though their graphs are going blank while mine are behaving crazy):
Plotly: How to prevent graphs from going blank when there are too many interactive plots?
However I did not manage to find/change the jupyter configuration file, maybe because I installed it via Anaconda?
I was also wondering if someone experienced exactly the same or there might be a simpler solution to this issue.
Thanks a lot in advance
I believe that in the second link the config file should be generated if not existing.
You can also try changing to gl rendering:
https://plotly.com/python/webgl-vs-svg/
How to do upload my interactive bokeh maps I created on a website? I read the documentation and used the file_html function to create the html code, but all the functionality does not work like the select drop down, and sliders. What is the best way to share it on a website?
This is the warning I received.
This is the Warning I received. WARNING:bokeh.embed.util: You are generating
standalone HTML/JS output, but trying to use real Python callbacks (i.e.
with on_change or on_event). This combination cannot work. Only JavaScript
callbacks may be used with standalone output. For more information on
JavaScript callbacks with Bokeh , see:
http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html
I tried to make that error message as self-contained as possible. I am not sure what else can be added to it, but suggestions are welcome. There are two scenarios:
Standalone output
This is purely HTML and JS content, that has no connection with any running python process. It is most often generated with output_file and show (or save), but it's also what you get if you use the lower level file_html function. Since there is no Python process anywhere after the output is created, there is no possible way for "real" Python callbacks to function, at all. In this case, the only possible callbacks that can work are JavaScript ones, e.g. CustomJS added with js_on_change or js_on_event. That's because the browser viewing the (purely HTML and JS) content does not know anything about Python, it only knows about JavaScript.
Bokeh Server Applications
This is a continuously running Bokeh server that serves Bokeh content, and,
most crucially: maintains an active connection to that content. That means that when some event happens, e.g. a slider changes, the Bokeh server can run real Python callback code in response. That is, in fact, the primary reason the Bokeh server exists: to be the thing that runs real Python code for an on_change or on_event callbacks. If you want to run real Python code (e.g. Numpy or Pandas or whatever) in response to events, you must run a Bokeh server.
Right click on the generated site in a web browser and select "Inspect". Then open the "console" tab and you list of errors will be detailed there. My guess is that you are not referencing a javascript file correctly.
I’m building a GUI (pyqt or pyside) to easily create complex figures (e.g. with plotly) for users.
So far so good, I run the data processing and produce plotly figures that are exported as html and read by QwebEngineView. I even created a qt widget for layout editing by the user (see image below).
The problem with this is the long delay (few seconds) in the process of:
updating the layout -> exporting to a temp html file → open and rendering the file on GUI.
I want to make a better GUI experience with layout editing.
Following this great Jon Mease talk I discovered my plotly figures could be updated in real time using the also great ipywidgets, but only on Jupyter notebooks / lab environment. That is, exporting the widgets+figure to a html file renders all elements, but since the python backend will be lacking for the widgets (in the standalone html file), they won’t interact with the figure’s layout.
However, my application IS running on a python process, so I have the feeling this should be a solvable problem somehow...
Qtconsole won’t render ipywidgets, so I can’t use it to expose my figures in the GUI.
Voila renders Jupyter notebooks with interactive widgets, I’m not sure however if I could access it and incorporate it to the GUI. It says it can work both as a “standalone tornado application” or as a “server extension to notebook or jupyter_server”.
I’m aware there’s probably not a final solution to that, but I would appreciate any suggestions on how to approach this problem! Thanks!
I ended up creating a solution for the problem: QtVoila
It is basically an extended QWebEngineView that manages and renders a Voila process, with some extra functionalities.
Here's a blog post explaining it:
https://www.taufferconsulting.com/portfolio/qtvoila
I use Bokeh to plot some interactive charts for my project, the Bokeh app runs on server. I like these charts can be plotted in full size on clients' browsers no matter what local resolution would be. Could someone give me a clue on how to get remote screen's max size?
I tried selenium, which asks user install drivers on local computer. It is not a good idea.
Also I tried python win32 API, which gets server's not remote computer's resolution.
Thanks
I don't know how to get the screen's size, but I have made my bokeh figures take up the full browser window (not necessarily full screen, but would be if the browser was full screen).
Instead of:
figure(plot_width = ... , plot_height = ... , ...)
I used:
figure(sizing_mode="stretch_both", ...)
("scale_both" is an alternative, which keeps the height/width ratio if you set those too).
Info from bokeh documentation.
When using the web based iPython Notebook/Jupyter capability, i created a notebook with markdown cells of text and code cells to display the code and plots for matplotlib and bokeh. I then download that as .ipynb open with sublime, copy and paste to git, then access it on nbviewer through my git account. When looking at it here:
http://nbviewer.ipython.org/github/angisgrate/test/blob/master/pyohio3.ipynb
in notebook view, it works fine. the markdown, code, and plot steps are all there.
When switching to slides view, the intent of the creation needed for the presentation, this code blocks occurs first, blocking out the first 10 markdown steps and all the matplotlib steps, rendering this weird code without the plots:
http://nbviewer.ipython.org/format/slides/github/angisgrate/test/blob/master/pyohio3.ipynb
How can i fix this asap?? I've looked through and there was a similar problem in 2014 with slides, but it yielded an actual "Error" that i'm not seeing, just this contorted view
I can't say for certain. It's possible in the nbviewer slides view, the execution of JavaScript is suppressed (this happens on GitHub notebook previews, for instance). All of the rendering in Bokeh actually happens from the JavaScript library BokehJS, so if this is the case, then Bokeh will not function, and there is nothing really that can be done. This is probably a question bset directed towards the nbviewer team/community to find out the specifics of how the slides view behaves (and is intended to behave) with respect to executing embedded JavaScript.
Edit: Looks like this is a known/discussed issue. More information here: Issue #484: Jupyter>>nbviewer slides Fail, notebook view fine by angisgrate in jupyter/nbviewer on GitHub