Shiny 如何在一个闪亮的选项卡中输出RMarkdown文件(使用参数运行)
我想在一个闪亮的选项卡中显示一个RMarkdown文件。问题是,只有在没有显式传递到RMarkdown文件的参数时,它才起作用。随附的文件对应于一个闪亮的应用程序,它有两个选项卡:一个带有下载按钮(按预期工作),另一个显示RMarkdown报告的输出(但不带参数) 你知道怎么做吗 接下来嵌入了2个文件。数据文件是common iris.csv 闪亮的应用程序代码(shinyMinimal.R):Shiny 如何在一个闪亮的选项卡中输出RMarkdown文件(使用参数运行),shiny,r-markdown,Shiny,R Markdown,我想在一个闪亮的选项卡中显示一个RMarkdown文件。问题是,只有在没有显式传递到RMarkdown文件的参数时,它才起作用。随附的文件对应于一个闪亮的应用程序,它有两个选项卡:一个带有下载按钮(按预期工作),另一个显示RMarkdown报告的输出(但不带参数) 你知道怎么做吗 接下来嵌入了2个文件。数据文件是common iris.csv 闪亮的应用程序代码(shinyMinimal.R): 库(rmarkdown) 图书馆(闪亮) 提苏伊 library(rmarkdown) librar
库(rmarkdown)
图书馆(闪亮)
提苏伊
library(rmarkdown)
library(shiny)
thisUI <- shinyUI(
fluidPage(
mainPanel(
tabsetPanel(
tabPanel("Report in webpage",
includeMarkdown("minimalReport.Rmd")
),
tabPanel("Download report",
flowLayout(
radioButtons('format', 'Document format', c('HTML', 'Word', 'PDF'),inline = TRUE
),
downloadButton(outputId = "downloadReport", label = "Download the report")
)
)
)
)
)
)
thisServer <- function(input, output) {
output$downloadReport <- downloadHandler(
filename = function() {
switch(
input$format,
PDF = base::paste('minimalReport', sep = '.','pdf'),
HTML = base::paste('minimalReport', sep = '.','html'),
Word = base::paste('minimalReport', sep = '.','docx')
)
},
content = function(nameOutputFile) {
nameInputThisFile <- "iris.csv"
paramsReportTwo <- list(n = 64, nameInputFile = nameInputThisFile)
inputRmdFile <- "minimalReport.Rmd"
rmarkdown::render(input = inputRmdFile,
params = paramsReportTwo,
output_file = nameOutputFile,
switch(input$format,
PDF = pdf_document(),
HTML = html_document(),
Word = word_document()
)
)
}
)
}
shiny::shinyApp(ui = thisUI, server = thisServer)
---
title: "Dynamic report"
output: html_document
params:
n: NA
nameInputFile: NA
---
There is some text.
```{r}
# The `params` object is available in the document.
params$n
```
A plot of `r params$n` random points.
```{r}
plot(rnorm(params$n), rnorm(params$n))
```
Read from a file
```{r}
inputData <- readr::read_csv(params$nameInputFile)
```
The mean of first data column from file `r params$nameInputFile` is `r mean(inputData[[1]])`
And then show a table
```{r}
head(inputData)
```
The End