HTML widgets in Jupyter R Notebook

半城伤御伤魂 提交于 2019-12-05 23:14:50

问题


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


回答1:


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)


来源:https://stackoverflow.com/questions/34292161/html-widgets-in-jupyter-r-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!