r - 在 shinydashboard 框内放置 markdown 压缩页面

标签 r shiny r-markdown shinydashboard

我正在尝试将 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

这将创建以下内容:

Compressed

如果我切换到非 markdown 实现,例如:

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

我得到:

Normal

我期望的 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/

相关文章:

r - 如何在数据框其他列的一列中搜索字符串

r - 从对象名称中提取元素

r - 在Word文档中使用DiagrammeR(使用rMarkdown生成)

r - 德国引号在 tinytex/rmarkdown 中损坏 - 即使使用包 `csquotes`

pdf - 在 Rmarkdown 文件中添加 pdf 文件

r - 根据特定行的条件创建一个新变量

mysql - R 中的 doParallel() 和 mySQL : Database not receiving data

r - 侧边栏菜单项之间的空间

html - 将 Markdown 另存为交互式 HTML

r - SelectInput 选项隐藏在 Shiny 应用程序中的下载按钮后面