首页 > 解决方案 > rmarkdown flexdashboard 中的热图

问题描述

我在插入两个选项卡式 flexdashboard rmarkdown 中的 plotly 热图对象时遇到了一个非常具体的问题。下面的 MRE 在渲染时显示未捕获的轴调整大小 javascript 错误。该错误导致数据表和热图无法呈现。但是,如果将热图移动到同一个选项卡,两者都将毫无问题地呈现。最疯狂的部分是在打开第二个选项卡的情况下对 html 文档(浏览器中的 ctrl+f5)进行硬刷新会导致 javascript 错误消失并且一切都呈现得很好。我很难将此问题隔离到 plotly R API 或 R 包 htmlwidgets。有任何想法吗?

---
title: "`r paste0('Test')`"
date: "`r Sys.Date()`"
output: 
  flexdashboard::flex_dashboard:
    vertical_layout: scroll
    orientation: rows
    self_contained: false
---

```{r setup, include=FALSE}
library(flexdashboard)
library(reshape2)
library(dplyr)
library(ggplot2)
library(plotly)
```



Tab1
===================================================

Row
-----------------------------------------------------------------------

### A scatter

```{r fig1}
df = data.frame(x = 1:5, y = 1:5, z = 1:5)
plot_ly(df, x = ~x, y = ~y, type = "scatter")
```

Row
-----------------------------------------------------------------------

### A table

```{r table1}
DT::datatable(df,
                filter="top",extensions = 'Buttons',
  options = list(
      dom = 'Bfrtip',
      buttons = c('copy', 'csv', 'excel'),
      pagelength=50,
      autoWidth=T,
      deferRender = T
  )
)
```

Tab2 
===================================================

Row
-----------------------------------------------------------------------

### A heatmap

```{r fig2}
plot_ly(df, x = ~x, y = ~y, z = ~z, type = "heatmap")
```

标签: rr-markdownplotlyflexdashboardhtmlwidgets

解决方案


推荐阅读