首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用includeHTML时,sidebarMenu无法正常运行

使用includeHTML时,sidebarMenu无法正常运行
EN

Stack Overflow用户
提问于 2018-05-20 04:14:17
回答 1查看 872关注 0票数 12

我正在使用Rshinydashboard,当我尝试使用includeHTML在我的应用程序中包含一个html文档时,我遇到了一个问题。一旦menuItems和menSubItems被展开,它们就不能被收回。我已经探索了其他解决方案,但没有找到任何解决方案。如果你有任何想法可能是什么问题,或有其他方法包括一个应用程序中的html报告,我将感谢您的帮助。请看下面的代码,如果可以的话请帮助!

创建一个RMD文件来创建一个html报告(如果您没有现成的报告)

代码语言:javascript
复制
---
title: "test"
output: html_document
---
## Test HTML Document
This is just a test.

构建一个测试html报告

代码语言:javascript
复制
# Build Test HTML file
rmarkdown::render(
  input = "~/test.rmd",
  output_format = "html_document",
  output_file = file.path(tempdir(), "Test.html")
)

构建测试应用

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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")))

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50429119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档