问题
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