Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML widgets in Jupyter R Notebook

Im unable to display HTML widgets in Jupyter Notebooks when using R (works when using python). For example none of the plotly charts work in Jupyter R notebook. Is there any solution for this?

library(plotly)
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
plot_ly(d, x = carat, y = price, text = paste("Clarity: ", clarity),
        mode = "markers", color = carat, size = carat)

The code executes but no graph is displayed

like image 615
Jeereddy Avatar asked Dec 15 '15 14:12

Jeereddy


People also ask

Can we use HTML in Jupyter Notebook?

Jupyter Notebook Markdown allows you to use raw HTML in Markdown cells.

What are HTML widgets R?

The htmlwidgets package provides a framework for easily creating R bindings to JavaScript libraries. Widgets created using the framework can be: Used at the R console for data analysis just like conventional R plots (via RStudio Viewer).


1 Answers

You need to make a call to embed_notebook (see the examples here).

So change your code to:

library(plotly)
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
myPlot <- plot_ly(d, x = carat, y = price, text = paste("Clarity: ", clarity),
        mode = "markers", color = carat, size = carat)
embed_notebook(myPlot)
like image 156
Bradley Marques Avatar answered Sep 24 '22 19:09

Bradley Marques