I am using Rshinydashboard and I have ran into an issue when I try and include a html document in my app using includeHTML. Once the menuItems & menSubItems are expanded, they can not be retracted. I have explored other solutions and have found none. If you have any idea what may be the problem or have another way of including a html report in an app I would appreciate your help. Please see the code below and help if you can!
Create a RMD file to create a html report (if you don't have one lying around)
---
title: "test"
output: html_document
---
## Test HTML Document
This is just a test.
Build a Test html Report
# Build Test HTML file
rmarkdown::render(
input = "~/test.rmd",
output_format = "html_document",
output_file = file.path(tempdir(), "Test.html")
)
Build Test App
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)
That is because you included a complete HTML file in the shiny UI, and
you should only include the content between <body>
and </body>
(quoted from yihui)
A solution could be to run an extra line to fix your Test.html
automatically after running rmarkdown::render()
:
xml2::write_html(rvest::html_node(xml2::read_html("Test.html"), "body"), file = "Test2.html")
and then have
output$uia <- renderUI(includeHTML(path = file.path(tempdir(), "Test2.html")))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With