I am learning Shinyapps.io and shiny. I hope to use it for teaching. I would like to run some computations, generate from Rmd an html file and show the user that html file in user's Browser in a NEW tab. I can do this on my Windows 7 with RStudio using Pander's openFileInOS. I can show this html file in shiny tab using Render .... but not in a NEW tab in the Browser. How do I do this?
# 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)
any rmd file. here is report.rmd file code
---
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
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
Including Plots
You can also embed plots, for example:
plot(pressure)
Note that the echo = FALSE
parameter was added to the code chunk to prevent printing of the R code that generated the plot.