0

The following is the simplified R Shiny app code to include a HTML file converted from a R markdown file using rmarkdown library.

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

ui <- dashboardPage(
  dashboardHeader(title = "Basic Dashboard"),
  dashboardSidebar(
    sidebarMenu(id="menu1",
                menuItem("tab title1", tabName = "name1", 
                icon = icon("sliders")),
                menuItem("tab title2", tabName =  "name2", 
                icon = icon("sliders"))
    ),
    conditionalPanel(
      condition = "input.menu1 == 'name2'",
      selectInput("period", "Period:", 
                  choices = list("Years" = 1, "Months" = 2))
    )
  ),
  dashboardBody(
    tabItem(tabName = 'name1', uiOutput("about"))
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
  if (!file.exists("www/about.html") || file.info("www/about.Rmd")$mtime > 
                                        file.info("www/about.html")$mtime) {
    # Convert the Rmd file to HTML
    rmarkdown::render("www/about.Rmd", clean = TRUE, quiet = TRUE)
  }
  output$about <- renderUI({
    includeHTML("www/about.html")
  })
}

# Run the application
shinyApp(ui = ui, server = server)

The R markdown file is simply stating:

---
title: "About Page"
output: 
  html_document:
    theme: yeti
---

## About Page

Whenever the HTML file is included as shown above, the conditional panel is not working.

Looks like there are some conflicts between the scripts used by R Shiny Dashboard and rmarkdown theme. I wonder there are ways to prevent such conflicts while maintaining the theme of Rmd-based HTML and enabling the conditional panel functionalities.

kjetil b halvorsen
  • 1,206
  • 2
  • 18
  • 28
ikaika
  • 1
  • 2

1 Answers1

0

The issue is resolved if you delete everything outside of the <body> tags in the rendered HTML document. I am unsure why this happens, but it has always been my go-to solution.

Adam
  • 1
  • 1
  • Welcome to SO Adam. While your solution may solve the OP's issue, it is better to provide a working example so that others can see that it works. Doing so makes it easier for people to assess your answer, and also increases your chances of upvotes. Thanks – L Tyrone May 16 '23 at 23:27