Mohamed Osman
Mohamed Osman

Reputation: 133

Layout in R Shiny app that include R Markdown file

I am facing a problem with the layout in R Shiny when I use the R Markdown file inside it I get the final result in a wired layout size (small and only in the middle of the screen ) as shown in the following photo: enter image description here

Attached to you the code:

library(shiny)
library(shinydashboard)
library(knitr)

ui <- 
dashboardPage(
  dashboardHeader(title ='Virtual Excursion'), 
  
  dashboardSidebar( sliderTextInput(
    inputId = "mySliderText", 
    label = "Story line", 
    grid = TRUE, 
    force_edges = TRUE,
    choices = c('1','2')
  )
  ),
  dashboardBody(
    fluidRow(
      column(9,  
             box(
               title = "Operations ", 
               closable = FALSE, 
               width = 9,
               status = "primary", 
               solidHeader = FALSE, 
               collapsible = TRUE,
               uiOutput("operations")
             )
      )
    ), 
    fluidRow(
      column(9, 
             box(
               title = "Challenges", 
               closable = FALSE, 
               width = 9,
               status = "primary", 
               solidHeader = FALSE, 
               collapsible = TRUE,
               uiOutput("challenges")
             )
      ) 
    )
  )
)


 server <- function(input, output,session){

 output$operations <- renderUI({
 req(input$mySliderText==1)

 HTML(markdown::markdownToHTML(knit('trial1.rmd', quiet = TRUE)))
 })
}
shinyApp(ui = ui, server = server)

Could you please guide me on how to fix this problem!

Upvotes: 1

Views: 878

Answers (1)

guasi
guasi

Reputation: 1769

The problem is that you are including an full html file within an html page. The conflicts between the two pages is causing the display problem. You need to output an html fragment which excludes the heading. Add fragment.only = TRUE to your markdown render function.

HTML(markdown::markdownToHTML(knit("trial1.rmd", quiet=T),fragment.only = T))

You can also add output: html_fragment in your yaml section inside the rmd file for good measure.

Upvotes: 1

Related Questions