RStudio 中 r-markdown 中的绘图显示为灰色且非交互式预览

发布于 2025-01-14 13:06:06 字数 951 浏览 1 评论 0原文

昨天我更新了 RStudio 和 R,从那时起我的大部分 Markdowns 都无法再显示plotly的交互式绘图了。相反,我得到了一个灰色的图(它显示了正确的图,但它是灰色的且非交互式)

相同的降价在我的另一台装有旧 R 和 RStudio 的电脑上仍然完美地工作。

我发现任何类型的控制台输出(参见“我不工作”)都会抑制交互。 此外,如果我在同一块中绘制多个图,它也会变成灰色且不可交互(请参阅“不工作 II”)。 如果我只有一个图并将其设置为不显示控制台消息,我仍然会得到一个交互式图。

知道问题是什么吗?

编辑:此外,如果我编织,我会得到“完美”的图(交互式而不是灰色)

这是一个显示问题的最小工作示例:

---
title: "Untitled"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(plotly)
```  

```{r Not Working I}  
plot_ly(economics, x = ~date, y = ~unemploy / pop)
```

```{r Working I}
plot_ly(economics, x = ~date, y = ~unemploy / pop, 
             type = "scatter", mode="markers")
```

```{r Not Working II}
plot_ly(economics, x = ~date, y = ~unemploy / pop, 
             type = "scatter", mode="markers")

plot_ly(economics, x = ~date, y = ~unemploy / pop, 
             type = "scatter", mode="markers")
```

Yesterday I updated RStudio and R, and since then most of my markdowns cannot show interactive plots of plotly anymore. Instead I get a greyed out plot (which shows the correct plot, but it is grey and non interactive)

The same markdown works still perfectly on my other PC with the old R and RStudio.

I figured out that any kind of console output (see "Not Working I") supresses the interaction.
Also if I plot multiple plots in the same chunk, it also becomes grey and non-interactive (see "Not Working II").
If I just have one plot and I set it up so that no console message is shown, I still get an interactive plot.

Any idea what the issue could be?

EDIT: Also if I knit I get "perfect" plots (interactive and not grey)

Here is a minimum working example which shows the problem:

---
title: "Untitled"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(plotly)
```  

```{r Not Working I}  
plot_ly(economics, x = ~date, y = ~unemploy / pop)
```

```{r Working I}
plot_ly(economics, x = ~date, y = ~unemploy / pop, 
             type = "scatter", mode="markers")
```

```{r Not Working II}
plot_ly(economics, x = ~date, y = ~unemploy / pop, 
             type = "scatter", mode="markers")

plot_ly(economics, x = ~date, y = ~unemploy / pop, 
             type = "scatter", mode="markers")
```

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独行侠 2025-01-21 13:06:06

尝试设置
knitr::opts_chunk$set(警告 = FALSE)
我之前也遇到过同样的问题,这解决了它。
但考虑到您正在禁用警告,这可能不是最好的解决方案。目前正在尝试寻找此快速修复的替代方案。也许您已经找到了解决方案。

Try setting
knitr::opts_chunk$set(warning = FALSE).
I was having the same issue before and this solved it.
But its probably not the best solution considering that you are disabling warnings. Currently trying to find an alternative to this quick fix. Perhaps you already found a solution.

暖心男生 2025-01-21 13:06:06

据报道,这是一个错误,已在当前日报中修复:https://dailies.rstudio.com/

该修复也将向后移植到当前版本中。

It reportedly was a bug which was already fixed with the current daily: https://dailies.rstudio.com/

The fix will also be backported into the current release.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文