使用闪亮仪表板在 R Shiny 应用程序中包含从 RMarkdown 渲染的 HTML 文件会导致 tabItems 损坏

2024-03-05

Problem

当使用shinydashboard在ShinyApp中包含从RMarkdown渲染的HTML文档时,只有当RMarkdown文件的YAML块中的设置“self_contained:”设置为true时,HTML文档才能正确渲染。但是,这样做会导致您无法从闪亮仪表板的侧边栏菜单中选择 tabItems。

相反,当设置“self_contained:”设置为 false 时,HTML 文档的元素(例如绘图和浮动目录) 缺少(附加文件中存在非 HTML 元素),但您可以从侧边栏菜单中选择 tabItems,并且应用程序的其余部分工作正常。

理想情况下,您将能够在闪亮仪表板中包含从 RMarkdown 渲染的功能齐全的 HTML 文件,同时保留应用程序其余部分的功能。

我之前关于如何在基本的 Shiny 应用程序中包含 HTML 的文章提到了这个额外的问题(在 R Shiny 应用程序中渲染 R Markdown 文档时参考书目不起作用 https://stackoverflow.com/questions/64368840/bibliography-not-working-when-rendering-a-r-markdown-document-within-an-r-shiny).

请在下面找到一个最小的可重现示例。

最小可重复示例

RMarkdown 文件

RMarkdownFile.Rmd

---
title: "RMarkdownFile"
author: "Test Author"
date: "15/10/2020"
output: 
  html_document:
    toc: true
    toc_float: true
    number_sections: true
    self_contained: true
bibliography: bibliography.bib
link-citations: yes
---

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

library(ggplot2)

```


# Statement

ggplot2 [@wickham2016ggplot2] is a great package!

```{r plot, message=FALSE}

ggplot2::ggplot(data = mpg) + 
  ggplot2::geom_point(mapping = aes(x = displ, y = hwy))
  
```

## References

参考书目

参考书目.bib

@book{wickham2016ggplot2,
  title={ggplot2: elegant graphics for data analysis},
  author={Wickham, Hadley},
  year={2016},
  publisher={springer}
}

闪亮的应用程序

app.R

library(shiny)
library(shinydashboard)
library(rmarkdown)

rmarkdown::render("RMarkdownFile.Rmd")

ui <- dashboardPage(
  
  dashboardHeader(title = "Test"),
  
  dashboardSidebar(
    sidebarMenu(id = "sidebarmenu",
                
                menuItem("Test Section 1", tabName = "testitem1",
                         menuSubItem("Test Section 1a", tabName = "testitem1a"),
                         menuSubItem("Test Section 1b", tabName = "testitem1b")
                         ),
                
                menuItem("Test Section 2", tabName = "testitem2",
                         menuSubItem("Test Section 2a", tabName = "testitem2a"),
                         menuSubItem("Test Section 2b", tabName = "testitem2b")
                         ),
                
                menuItem("Test Section HTML", tabName = "testitemhtml"
                         )
                )
    ),
  
  dashboardBody(
    
    tabItems(
    
      tabItem(tabName = "testitem1a",
              fluidRow(
                box(title = "Test Section 1a",
                    width = 12))
              ),
              
      tabItem(tabName = "testitem1b",
              fluidRow(
                box(title = "Test Section 1b",
                    width = 12))
              ),
              
      tabItem(tabName = "testitem2a",
              fluidRow(
                box(title = "Test Section 2a",
                    width = 12))
              ),
              
      tabItem(tabName = "testitem2b",
              fluidRow(
                box(title = "Test Section 2b",
                    width = 12))
              ),
              
      tabItem(tabName = "testitemhtml",
              fluidPage(
                box(title = "Test Section HTML",
                    width = 12,
                    includeHTML("RMarkdownFile.html")))
              )
      )
    )
)
  
  
  

server <- function(input, output) { }

shinyApp(ui, server)

任何解决此问题的帮助将不胜感激!


Stéphane 在上面的评论中解决了这个问题!

请在下面找到最小可重现示例 app.R 的工作版本:

library(shiny)
library(shinydashboard)
library(rmarkdown)

rmarkdown::render("RMarkdownFile.Rmd")

ui <- dashboardPage(
  
  dashboardHeader(title = "Test"),
  
  dashboardSidebar(
    sidebarMenu(id = "sidebarmenu",
                
                menuItem("Test Section 1", tabName = "testitem1",
                         menuSubItem("Test Section 1a", tabName = "testitem1a"),
                         menuSubItem("Test Section 1b", tabName = "testitem1b")
                         ),
                
                menuItem("Test Section 2", tabName = "testitem2",
                         menuSubItem("Test Section 2a", tabName = "testitem2a"),
                         menuSubItem("Test Section 2b", tabName = "testitem2b")
                         ),
                
                menuItem("Test Section HTML", tabName = "testitemhtml"
                         )
                )
    ),
  
  dashboardBody(
    
    tabItems(
    
      tabItem(tabName = "testitem1a",
              fluidRow(
                box(title = "Test Section 1a",
                    width = 12))
              ),
              
      tabItem(tabName = "testitem1b",
              fluidRow(
                box(title = "Test Section 1b",
                    width = 12))
              ),
              
      tabItem(tabName = "testitem2a",
              fluidRow(
                box(title = "Test Section 2a",
                    width = 12))
              ),
              
      tabItem(tabName = "testitem2b",
              fluidRow(
                box(title = "Test Section 2b",
                    width = 12))
              ),
              
      tabItem(tabName = "testitemhtml",
              fluidPage(
                htmltools::tags$iframe(src = "RMarkdownFile.html", width = '100%',  height = 1000,  style = "border:none;"))
              )
      )
    )
)
  
  
  

server <- function(input, output) { }

shinyApp(ui, server)

为了使此解决方案起作用,必须手动将“RMarkdownFile.html”文件放置在 Shiny 应用程序目录中名为“www”的文件夹中,除非“RMarkdownFile.Rmd”文件直接呈现到此“www”文件夹。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用闪亮仪表板在 R Shiny 应用程序中包含从 RMarkdown 渲染的 HTML 文件会导致 tabItems 损坏 的相关文章

  • 设置浏览器窗口最小化的最小尺寸限制?

    有没有办法在所有浏览器中手动设置浏览器窗口的最小尺寸 你可以试试 body min width 600px 一旦视口小于 600 像素 您将得到一个水平滚动条 这仅适用于支持 min width CSS 属性的现代浏览器 我认为不可能限制用
  • 对一组复选框使用 HTML5“必需”属性?

    使用支持 HTML5 的较新浏览器 例如 FireFox 4 时 并且表单字段具有属性required required 并且表单字段为空 空白 然后点击提交按钮 浏览器检测到 必填 字段为空 并且不提交表单 相反 浏览器会显示一条提示 要
  • 如何将udp发送到udp node.js服务器?

    我对此很陌生 所以我真的不知道我在做什么 但我已经设置了一个 node js udp 服务器 我想从客户端 来自网站 向它发送一个数据包 但我不知道如何在 javascript 中做到这一点 或者是否可能 我不是在研究如何从 Node js
  • 在 Google Colab 上的 R 笔记本中安装 python 库

    我正在尝试在 Google Colab 上的 R 笔记本中安装 python 库 为此我使用 reticulate 包 library reticulate py install pandas 但我得到的结果是这个错误 Error coul
  • VBA / HTML / jQuery 选择自动完成 - 在列表中选择

    我正在尝试使用 Excel 中的 VBA 在网站的列表中选择一个值 这不是一个 正常列表 该网站使用 jQuery 选择自动完成 如下所示 example http davidwalsh name demo jquery chosen ph
  • 无法编译包“maps”

    当我安装 maps 包时 安装中出现警告 ld warning ignoring file Library Developer CommandLineTools SDKs MacOSX10 14 sdk usr lib libSystem
  • 我如何查看 quantmod 包中所有可用的数据系列?

    如何显示可用的所有报价 数据系列的列表 例如使用雅虎的 getSymbols 我不知道有什么办法 TTR包有一个功能 stockSymbols 下载 NYSE AMEX 和 NASDAQ 的所有当前代码 它试图将它们采用雅虎可接受的格式 但
  • 无法将“gather”输出的列名称更改为默认名称以外的任何名称

    我正在尝试使用gather in the tidyr包 但我无法更改默认名称的输出列名称 例如 df data frame time 1 100 a 1 100 b 101 200 df long df gt gather foo bar
  • R 数据结构的运算效率

    我想知道是否有任何关于操作效率的文档R 特别是那些与数据操作相关的 例如 我认为向数据框添加列是有效的 因为我猜您只是向链接列表添加一个元素 我想添加行会更慢 因为向量保存在数组中C level你必须分配一个新的长度数组n 1并将所有元素复
  • 如何使用 JavaScript 获取没有 HTML 元素的纯文本?

    我的 HTML 中有 1 按钮和一些文本 如下所示 function get content I don t know how to do in here
  • 如何通过php获取网页的Open Graph协议?

    PHP 有一个简单的命令来获取网页的元标记 get meta tags 但这仅适用于具有名称属性的元标记 然而 开放图谱协议如今变得越来越流行 从网页获取 opg 值的最简单方法是什么 例如 我看到的基本方法是通过 cURL 获取页面并使用
  • 在闪亮的数据表中为每个单元格显示工具提示或弹出窗口?

    有没有什么方法可以为 r闪亮数据表中的每个单元格获取工具提示 有很多方法可以获取悬停行或列 但我找不到一种方法来获取行和列索引并为每个单元格显示不同的悬停工具提示 任何人都可以修改以下代码吗 library shiny library DT
  • Google Chrome 106 可拖动导致元素消失

    使用拖放元素时 绝对定位元素中包含的大多数其他元素都会从屏幕上消失 如果我调整窗口大小 这些元素会出现 但在开始拖动时会再次消失 我在最新版本的 Google Chrome 106 和 Beta 版本 107 0 5304 18 以及现在的
  • ggplot2:带有 geom_line 的 x 轴因子不起作用

    我想要一个线图 其中value绘制为函数expt每级一行var 这是我的数据 lines lt expt var value 1 none p 0 183065327746799 2 none p 0 254234138384241 3 n
  • 如何将送货地址复制到帐单地址

    我想知道是否可以将送货地址复制到帐单地址 当用户单击与送货地址相同的复选框时 送货地址值将被复制到账单输入字段 我完成了大部分部分 但我不确定如何将选择菜单 状态 值复制到帐单地址 我真的很感谢任何帮助 My code document r
  • 使用data.table进行聚合

    经过 SO 用户的多次建议后 我终于尝试将我的代码转换为使用data table library data table DT lt data table plate paste0 plate rep 1 2 each 5 id rep c
  • 悬停时为 SVG 制作动画

    我正在尝试在悬停时为 SVG 文件设置动画 默认情况下 它可以使用 svg 函数实现出色的动画效果 例如
  • 如何获取 UIWebView 中元素的位置?

    我在 iPad 程序中加载了 html 的 UIWebView 通过使用 webkit column width 我将 html 分为几列 padding 0px height 1024px webkit column gap 0px we
  • 更改ggplot2中的字体

    曾几何时 我改变了我的ggplot2字体使用windowsFonts Times windowsFont TT Times New Roman 现在 我无法摆脱这一切 在尝试设置family in ggplot2 theme 当我用不同的字
  • 三级十进制有序列表 CSS

    我有一个 html 中的三级有序列表 我想为其提供如下样式 1 Item 1 1 1 Item 2 1 1 1 Item 3 下一个 plunker 中有一个 html 示例 http plnkr co edit DqhZ5pJILTUHG

随机推荐