我正在尝试将 markdown 嵌入到 shinydashboard 框中,稍后将部署到 shiny 服务器上。使用解决方案 here ,我创建了以下内容:
ui.R
library(shinydashboard)
dashboardPage(
dashboardHeader(title = "xxx"),
dashboardSidebar(),
dashboardBody(
column(
box(
title = "BoxTest",
uiOutput('mymarkdown'),
width = NULL
),
width = 8)
)
)
服务器.R
library(shiny)
library(knitr)
shinyServer(function(input, output) {
output$mymarkdown <- renderUI(HTML(markdown::markdownToHTML(knit("mymarkdown.Rmd", quiet = TRUE))))
})
我的markdown.Rmd
## R Markdown
Test Test Test
这将创建以下内容:
如果我切换到非 markdown 实现,例如:
output$mymarkdown <- renderUI(h4("Test Test Test"))
我得到:
我期望的 View 。
有什么方法可以避免这种页面压缩,或者有其他方法可以在 shinydashboard 框中部署 Markdown 文本吗?
最佳答案
我也在 shiny 中使用了 markdown,但是使用了 rmarkdown 和 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)
关于r - 在 shinydashboard 框内放置 markdown 压缩页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39357208/