Chris Chris - 2 months ago 27
R Question

Placing markdown within shinydashboard box compresses page

I am trying to embed markdown within a shinydashboard box, to be later deployed on a shiny server. Using the solution here, I have created the following:

ui.R



library(shinydashboard)

dashboardPage(
dashboardHeader(title = "xxx"),
dashboardSidebar(),
dashboardBody(
column(
box(
title = "BoxTest",
uiOutput('mymarkdown'),
width = NULL
),
width = 8)
)
)


server.R



library(shiny)
library(knitr)
shinyServer(function(input, output) {

output$mymarkdown <- renderUI(HTML(markdown::markdownToHTML(knit("mymarkdown.Rmd", quiet = TRUE))))

})


mymarkdown.Rmd



## R Markdown

Test Test Test


This creates the following:

Compressed

If I switch to a non-markdown implementation, for example:

output$mymarkdown <- renderUI(h4("Test Test Test"))


I get:

Normal

the view I would expect.

Is there any way to avoid this compression of the page, or is there another way to deploy markdown text in a shinydashboard box?

Answer

I also used markdown in shiny, but with rmarkdown and includeHTML

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

ui <- dashboardPage(
  dashboardHeader(title = "xxx"),
  dashboardSidebar(),
  dashboardBody(
    column(
      box(
        title = "BoxTest",
         uiOutput('mymarkdown'),
        width = NULL
      ),
      width = 8)
  )
)   
server <- shinyServer(function(input, output) { 
    output$mymarkdown <- renderUI({  
         rmarkdown::render(input = "mymarkdown.Rmd",
                           output_format = html_document(self_contained = TRUE),
                           output_file = 'mymarkdown.html')  
         shiny::includeHTML('mymarkdown.html') 
                            }) 
} ) 
shinyApp(ui, server)
Comments