Problems with adding formula to Markdown in Shiny

牧云@^-^@ 提交于 2020-02-07 06:16:12

问题


I want to add text in a tabPanel which contains some formula. The ui looks like this:

library(markdown)
library(shiny) 

shinyUI(fluidPage(
  titlePanel("Test"),
      sidebarLayout(
        sidebarPanel(
          ),

    mainPanel(
      tabsetPanel(
        tabPanel('Text', includeMarkdown("post.rmd"))
        )

      )
    )
  )
)

And the markdown file looks like this:

This  is a text test.

### Equations
There are inline equations such as $y_i = \alpha + \beta x_i + e_i$.

And displayed formulas:

$$\frac{1}{1+\exp(-x)}$$

When I run this, I do not get the formula as wanted but like texted as above. I have followed the instruction from here

and changed the format to .md but it did not work. What am I doing wrong?


回答1:


In a linked discussion there are comments about rendering rmarkdown files. R shiny doesn't automatically render markdown file as html so you have to add: rmarkdown::render("post.Rmd"). You could also compile your markdown file beforehand as html and use includeHtml in that case just use code: includeHTML(("post.html"))

library(markdown)
library(shiny) 
server <- function(input, output) {

}

ui <- shinyUI(fluidPage(
  sidebarLayout(
    sidebarPanel(

    ),
    mainPanel(
          tabsetPanel(
        tabPanel('Text', includeMarkdown(rmarkdown::render("post.rmd")))
        )

    )
  )
))

shinyApp(ui = ui, server = server)


来源:https://stackoverflow.com/questions/27557122/problems-with-adding-formula-to-markdown-in-shiny

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!