Как открыть загруженный файл downloadHandler на вкладке NEW в браузере пользователя? - PullRequest
2 голосов
/ 29 апреля 2019

Я учу Shinyapps.io и блестящий.Я надеюсь использовать это для обучения.Я хотел бы выполнить некоторые вычисления, сгенерировать из Rmd html-файл и показать пользователю этот html-файл в браузере пользователя на вкладке NEW.Я могу сделать это на моем Windows 7 с RStudio, используя openFileInOS от Pander.Я могу показать этот HTML-файл в блестящей вкладке с помощью Render .... но не в новой вкладке в браузере.Как мне это сделать?

# 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

Это документ R Markdown.Markdown - это простой синтаксис форматирования для создания документов HTML, PDF и MS Word.Подробнее об использовании R Markdown см. http://rmarkdown.rstudio.com.

Когда вы нажмете кнопку Knit , будет создан документ, который включает в себя как содержимое, так и выходные данные любых фрагментов встроенного кода R в пределахдокумент.Вы можете встроить блок кода R следующим образом:

summary(cars)

Включая графики

Вы также можете вставлять графики, например:

plot(pressure)

Обратите внимание, что echo = FALSE параметр был добавлен в блок кода для предотвращения печати кода R, сгенерировавшего график.

...