rbokeh
rbokeh copied to clipboard
How to plot figures inline with iPython Jupyter/Notebook
Do you have an example of how to embed plots inline within an iPython Jupyter/Notebook? I've tried embedding HTML with the get_bokeh_html(fig) approach with no luck (results in an inline blank image notated with red font Javascript error. If I open the saved off html file I get the same errors )
JS errors in the JS console: Uncaught Error: field value for property 'x' is not a string (CDN calling Bokeh 0.9.1, 0.9.2) Uncaught TypeError: t.default_view is not a function (CDN calling Bokeh 0.8.1)
These are the relevant cells in my iPython Jupyter notebook
--- cell #1 ---
%%R
library(rbokeh)
p <- figure() %>%
ly_points(Sepal.Length, Sepal.Width, data = iris,
color = Species, glyph = Species,
hover = list(Sepal.Length, Sepal.Width))
h <- p
cat(get_bokeh_html(p), file="tryit.html")
--- cell #2 ---
%R -o h
--- cell #3 (bokeh 0.8.1 and 0.9.2 result in different JS errors) ---
blurb = h[0]
blurb = blurb.replace('0.8.1', '0.9.2')
blurb = blurb.replace('\n','')
--- cell #4 ---
from IPython.core.display import HTML
HTML(blurb)
This is a good question. I was asked this a few months ago. I don’t use jupyter but have been meaning to look into it. Have you been able to use any other htmlwidget with jupyter? I’m thinking if this were handled at the htmlwidget level that would be the best thing. I filed an issue here: https://github.com/ramnathv/htmlwidgets/issues/144 https://github.com/ramnathv/htmlwidgets/issues/144. Please join in the conversation there if you have suggestions.
Ryan
On Jul 30, 2015, at 6:23 PM, apoku [email protected] wrote:
Do you have an example of how to embed plots inline within an iPython Jupyter/Notebook? I've tried embedding HTML with the get_bokeh_html(fig) approach with no luck (results in an inline blank image notated with red font Javascript error. If I open the saved off html file I get the same errors )
JS errors in the JS console: Uncaught Error: field value for property 'x' is not a string (CDN calling Bokeh 0.9.1, 0.9.2) Uncaught TypeError: t.default_view is not a function (CDN calling Bokeh 0.8.1)
These are the relevant cells in my iPython Jupyter notebook
--- cell #1 --- %%R library(rbokeh) p <- figure() %>% ly_points(Sepal.Length, Sepal.Width, data = iris, color = Species, glyph = Species, hover = list(Sepal.Length, Sepal.Width))
h <- p cat(get_bokeh_html(p), file="tryit.html")
--- cell #2 --- %R -o h
--- cell #3 (bokeh 0.8.1 and 0.9.2 result in different JS errors) --- blurb = h[0] blurb = blurb.replace('0.8.1', '0.9.2') blurb = blurb.replace('\n','')
--- cell #4 --- from IPython.core.display import HTML
HTML(blurb) — Reply to this email directly or view it on GitHub https://github.com/bokeh/rbokeh/issues/112.
Thanks for the insight--I am just getting familiar with the R/Python/JS space and so don't have much experience with htmlwidgets. However, it does look like Bokeh proper has a mechanism for embedding generated HTML. Would the Bokeh dev team be able to provide some insight here?
http://bokeh.pydata.org/en/latest/docs/user_guide/embed.html http://bokeh.pydata.org/en/latest/docs/user_guide/embed.html#ipython-notebook http://bokeh.pydata.org/en/latest/docs/user_guide/embed.html#id2
Here: https://github.com/bokeh/bokeh/blob/master/bokeh/util/notebook.py#L8-L69, it is the code in charge to load BokehJS into the notebook... after loading the notebook with the js and css, you should embed the figures: https://github.com/bokeh/bokeh/blob/master/bokeh/io.py#L256-L262, and finally publish the html using the notebook display machinery: https://github.com/bokeh/bokeh/blob/master/bokeh/io.py#L256-L262
Hope it helps a little bit...
Hi, any progress on this issue? What's the roadblock? Is it in Jupyter, htmlwidgets or rbokeh? It would be awesome to get rbokeh working in Jupyter notebooks!
Thanks!
I agree!!
The roadblock for me is that I don't currently have a good understanding of the details of how to embed in Jupyter and I think this should be implemented at the htmlwidget level. @ramnathv, any new thoughts on this?
Also, see discussion here:
https://github.com/ramnathv/htmlwidgets/issues/144
https://github.com/ropensci/plotly/issues/398
Hi everybody,
You can still use gridplot([[a,b]]) in Jupyter to plot figures inline !
@JeanLescut I'm not sure I understand what you mean. Can you provide an example for embedding an rbokeh plot in a jupyter notebook?
I'm not sure of the status of a proper Jupyter embedding mechanisim. I currently rely on a shameful use of temporary html files in my Jupyter sessions.
library(rbokeh)
n <- nrow(cars)
ramp <- colorRampPalette(c("red", "blue"))(n)
p<-figure() %>%
ly_points(cars, color = ramp, size = seq_len(n))
rbokeh2html(p,'/mnt/out.html')
IRdisplay::display_html(file='/mnt/out.html')
Inexplicably, sometimes the last line needs to be rerun to ensure the Bokeh javascript is recognized. Is a better way in development?