r - 在闪亮的应用程序中渲染 r markdown 的 html 输出
问题描述
我正在尝试使用 r markdown 生成用于演示的 HTML 文档。现在,当我使用独立运行时,它似乎工作正常。但是当我在一个似乎不起作用的闪亮应用程序中使用它时。到目前为止,我已经在UI
includeHTML("mkslides.html")
并在服务器中使用它来呈现降价。
out <- render('mkslides.Rmd')
当我在闪亮的应用程序加载时看到控制台时,似乎会呈现降价。但我看到的只是 HTML 文件,不需要 css 和 js。我怎样才能解决这个问题?
解决方案
我不能 100% 确定您的目标,因此将尝试解决上述两点。
- 渲染 HTML 文档
ShinyApp
这非常简单,您需要做的就是includeHTML
在您UI.R
的 ShinyApp 部分中使用,不需要服务器端组件。
http://shiny.rstudio.com/gallery/including-html-text-and-markdown-files.html
注意: includeHTML
不呈现您的*.Rmd
文件。
- 在 a 中渲染 .Rmd 文件
ShinyApp
这需要knit
and markdownToHTML
,请参见下面的线程。
示例代码片段
示例 .Rmd 文件
---
title: "An example Knitr/R Markdown document"
output: html_document
---
{r chunk_name, include=FALSE}
x <- rnorm(100)
y <- 2*x + rnorm(100)
cor(x, y)
{r scatterplot, fig.width=8, fig.height=6}
plot(x,y)
上面另存为:
test_presentation.Rmd
和knit
作为test_presentation.html
1. 将HMTL
文件包含在Shiny
library(shiny)
ui <- shinyUI(
fluidPage(
includeHTML('test_presentation.html')
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
2.将上述*.Rmd
文件渲染在Shiny
代码形式:https ://stackoverflow.com/a/33500524/5996972
library(shiny)
library(knitr)
ui <- shinyUI(
fluidPage(
uiOutput('markdown')
)
)
server <- function(input, output) {
output$markdown <- renderUI({
HTML(markdown::markdownToHTML(knit('test_presentation.rmd', quiet = TRUE)))
})
}
shinyApp(ui, server)
推荐阅读
- php - 类 'App\GraphQL\Query\GraphQL' 未找到错误虽然包含在配置/应用程序中 - 服务提供者和别名
- c - 高强制级别应用程序的持久性 - windows
- r - geom_area 在层之间产生空白区域
- c# - 如何通过 Activator.CreateInstance 实例化对象并使用 Dapper 将其插入表中
- excel - Excel VBA 事件 - 单击了自动筛选按钮
- python - Python + Pandas:复制多个 CSV 第一行的特定列并将这些行存储到单个 csv
- python - Python中给定字符串中换行符搜索的正则表达式
- reactjs - TypeScript:TsLib 不包含 __importStar(__importStar 不是函数)
- spring-boot - 如何从一条路线获取标头到另一条路线 - Camel JavaDsl
- python - Numba - 如何并行填充二维数组