我正在学习Shinyapps.io并且很闪亮。我希望将其用于教学。 我想运行一些计算,从Rmd生成一个html文件,并在“新建”选项卡的用户浏览器中向用户显示该html文件。我可以使用Pander的openFileInOS在带有RStudio的Windows 7上执行此操作。我可以使用Render ....在闪亮的选项卡中显示此html文件,但不能在浏览器的“新建”选项卡中显示。我该怎么做?
# File Downloader. Needs report.rmd in the current directory to make it work
# https://shiny.rstudio.com/articles/generating-reports.html Winston Chang, July 2016
library(shiny)
library(here)
here::here()
ui = fluidPage(
sliderInput("slider", "Slider", 1, 100, 50),
downloadButton("report", "Generate report")
)
server = function(input, output) {
output$report <- downloadHandler(
# For PDF output, change this to "report.pdf"
filename = "report.html",
content = function(file) {
# Copy the report file to a temporary directory before processing it, in
# case we don't have write permissions to the current working dir (which
# can happen when deployed).
tempReport <- file.path(tempdir(), "report.Rmd")
file.copy("report.Rmd", tempReport, overwrite = TRUE)
# Set up parameters to pass to Rmd document
params <- list(n = input$slider)
# Knit the document, passing in the `params` list, and eval it in a
# child of the global environment (this isolates the code in the document
# from the code in this app).
rmarkdown::render(tempReport, output_file = file,
params = params,
envir = new.env(parent = globalenv())
) # downloads report.html
# ???
# How do I open the report.html file in a NEW tab in Browser, not a tab within Shiny?
#
# )
} # content ends
) # downloadHandler ends
} # server ends
shinyApp(ui = ui, server = server)
任何rmd文件。这是report.rmd文件代码
---
title: "Dummy Report"
author: "John Doe "
date: "April 13, 2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
这是R Markdown文档。 Markdown是用于编写HTML,PDF和MS Word文档的简单格式语法。有关使用R Markdown的更多详细信息,请参见http://rmarkdown.rstudio.com。
单击编织按钮时,将生成一个文档,其中包括内容以及该文档中任何嵌入式R代码块的输出。您可以像这样嵌入R代码块:
summary(cars)
您还可以嵌入图,例如:
plot(pressure)
请注意,echo = FALSE
参数已添加到代码块中,以防止打印生成绘图的R代码。