【发布时间】:2018-10-29 22:41:55
【问题描述】:
我正在使用 Rshinydashboard,当我尝试使用 includeHTML 在我的应用程序中包含一个 html 文档时遇到了问题。一旦 menuItems & menSubItems 被展开,它们就不能被收回。我探索了其他解决方案,但没有找到。如果您知道可能是什么问题,或者有另一种在应用程序中包含 html 报告的方式,我将不胜感激。请查看下面的代码,如果可以,请提供帮助!
创建一个 RMD 文件来创建一个 html 报告(如果你没有一个在附近)
---
title: "test"
output: html_document
---
## Test HTML Document
This is just a test.
构建测试 html 报告
# Build Test HTML file
rmarkdown::render(
input = "~/test.rmd",
output_format = "html_document",
output_file = file.path(tempdir(), "Test.html")
)
构建测试应用
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
id = "sidebarmenu",
menuItem(
"A", tabName = "a", icon = icon("group", lib="font-awesome"),
menuSubItem("AA", tabName = "aa"),
conditionalPanel(
"input.sidebarmenu === 'aa'",
sliderInput("b", "Under sidebarMenu", 1, 100, 50)
),
menuSubItem("AB", tabName = "ab")
)
)
),
dashboardBody(
tabItems(
tabItem(tabName = "a", textOutput("texta")),
tabItem(tabName = "aa", textOutput("textaa"), uiOutput("uia")),
tabItem(tabName = "ab", textOutput("textab"))
)
)
)
server <- function(input, output) {
output$texta <- renderText("showing tab A")
output$textaa <- renderText("showing tab AA")
output$textab <- renderText("showing tab AB")
output$uia <- renderUI(includeHTML(path = file.path(tempdir(), "Test.html")))
}
shinyApp(ui, server)
【问题讨论】:
-
我认为 rmarkdown 文件中的一个或多个 javascript 库导入与从 Shiny 加载的 javascript 库冲突。你可以渲染("~/test.rmd", html_document(self_contained = F))。注释掉所有 行,bug 就消失了,但这不是一个很好的解决方案。
-
请参阅 groups.google.com/forum/#!topic/shiny-discuss/0UiiHcdhN4k 了解有关此问题的讨论。
标签: r shiny shinydashboard