0

I have created a plot in R using rbokeh and I want to convert it to HTML/Javascript in order to embed it inside a web page. I'm currently able to achieve this with mpld3 on Python (and I know that bokeh on python does it too) but I want to be able to do this with rbokeh in R. So basically I'm looking for something similar to Python's mpld3.fig_to_html(), e.g:

fig, ax = plt.subplots()
ax.p1 = plt.bar(...)  
html = mpld3.fig_to_html(fig) # <- converts the plot to html/javascript!
print html   # prints out the html/javascript code as text

Or using Python's bokeh module: embed.autoload_static()

Can rbokeh plots be converted to html/JavaScript code?

Many thanks in advance.

bigreddot
  • 33,642
  • 5
  • 69
  • 122
en1
  • 237
  • 4
  • 8
  • 1
    I'm not familiar with rbokeh, but if you want something that's interactive in R then `shiny` is the answer for you. Unfortunately, it doesn't just work with any HTML page, it needs to be hosted on a shiny server or run locally. Look at shiny to learn more – DeanAttali Jun 19 '15 at 22:07
  • https://www.opencpu.org/ – user227710 Jun 19 '15 at 22:17
  • 1
    As demonstrated [here](https://rud.is/b/2015/05/26/a-quick-incomplete-comparison-of-ggplot2-rbokeh-plotting-idioms/) you can use `saveWidget` to save off the plots as HTML. – hrbrmstr Jun 20 '15 at 02:05
  • hrbrmstr, this is the closest I've come to what I want but not useful. I don't want to export the html/js code in a file, I want to be able to have it in a variable as string, which will be parsed by a server-side script and locally embedded into a web page via AJAX. Reading and parsing this html code from a file would not be efficient. – en1 Jun 21 '15 at 09:01

1 Answers1

0

It appears that, to date, saveWidget is the closest to what I want, so thanks hrbrmstr. I wanted to avoid having to read and write from the disk every time a graph is exported to html but it's not possible yet.

en1
  • 237
  • 4
  • 8