1

I am working on a Shiny app that needs to have a tab showing some help info to the user. I am trying to implement this feature by using the includeMarkdown function. I have example markdown file called ‘about.Rmd’ which contains some text, graph and an equation. Knitting the file in RStudio creates a file about.md

When I use the includeMarkdown function, the equation doesn’t display properly.

I am not doing something right but I am not sure what.

Below is the reprex example of the Shiny code:

library(shiny)
library(shinydashboard)
library(markdown)

# HEADER
header <- dashboardHeader(title = NULL, titleWidth = 310, disable = FALSE)
# SIDEBAR
sidebar <- dashboardSidebar(disable = TRUE)
# BODY
body <- dashboardBody(
  fluidRow(
    box(width = 2, title = "Input", status = "primary",solidHeader = TRUE, collapsible = FALSE,
    ),

    tabBox(width = 10, title = NULL, side = "left",
           id = "tabset1",
           tabPanel(h4("Result")

           ),

           tabPanel(h4("About"),
                    includeMarkdown("about.md")             #About page does not render the equation
           )
    )
  )
) # end of BODY

ui <- dashboardPage(header, sidebar, body, skin = "green")

server <- function(input, output) {}

shinyApp(ui, server)

Apologies in advance I am not providing the full ‘about.Rmd’ test file I am using but I couldn’t figure out how to make reprex for it. I will describe its content though. I am using the standard Rmd file generated by RStudio with the following modifications:

To the yaml header I have added a line ‘keep_md: TRUE’ so that the knitting generates also about.md file. I also added an equation at the bottom of the file: $f(k) = {n \choose k} p^{k} (1-p)^{n-k}$

That equation is not displayed properly.

Thank you for the help!

odar
  • 391
  • 1
  • 10
  • 1
    Hi, maybe you need to use `withMathJax`, see [this post](https://stackoverflow.com/questions/32101134/display-latex-equations-in-a-shiny-dashboard-app-in-r) for example – bretauv May 12 '20 at 17:58
  • 1
    @bretauv Thank you, this works great! – odar May 12 '20 at 18:17

1 Answers1

1

What I did is to create a new file (.md) with the app's documentation and then add it in the Shiny app.

[iu.R] ... 
tabPanel('How to use it?', uiOutput('markdown'))
...
[server.R] ... 
output$markdown <- renderUI({
    HTML(markdown::markdownToHTML('help.md'))
  })
...
jgarces
  • 519
  • 5
  • 17