Jupyter R Notebook中的HTML小部件 [英] HTML widgets in Jupyter R Notebook

查看:123
本文介绍了Jupyter R Notebook中的HTML小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用R时,无法在Jupyter Notebook中显示HTML窗口小部件(使用python时有效).例如,在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

推荐答案

您需要致电embed_notebook(请参见示例

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)

这篇关于Jupyter R Notebook中的HTML小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆