我正在学习 Shinyapps.io 和闪亮。我希望用它来教学。我想运行一些计算,从 Rmd 生成一个 html 文件,并在新选项卡中的用户浏览器中向用户显示该 html 文件。我可以使用 Pander 的 openFileInOS 在我的 Windows 7 上使用 RStudio 执行此操作。我可以使用 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 降价
这是一个 R Markdown 文档。Markdown 是一种用于创作 HTML、PDF 和 MS Word 文档的简单格式化语法。有关使用 R Markdown 的更多详细信息,请参阅http://rmarkdown.rstudio.com。
当您单击Knit按钮时,将生成一个文档,其中包括内容以及文档中任何嵌入式 R 代码块的输出。您可以像这样嵌入 R 代码块:
summary(cars)
包括地块
您还可以嵌入绘图,例如:
plot(pressure)
请注意,该echo = FALSE
参数已添加到代码块中以防止打印生成绘图的 R 代码。