我正在使用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)
发布于 2018-06-12 23:25:23
这是因为您在闪亮的UI中包含了一个完整的HTML文件,并且您应该只包含<body>
和</body>
之间的内容(引用自一会)。
一种解决方案是在运行rmarkdown::render()
之后运行额外的一行代码来自动修复您的Test.html
xml2::write_html(rvest::html_node(xml2::read_html("Test.html"), "body"), file = "Test2.html")
然后就有
output$uia <- renderUI(includeHTML(path = file.path(tempdir(), "Test2.html")))
https://stackoverflow.com/questions/50429119
复制相似问题