【问题标题】:Is there a way to have a user upload an image in an R Shiny app and have it render in a downloadable markdown report?有没有办法让用户在 R Shiny 应用程序中上传图像并在可下载的降价报告中呈现?
【发布时间】:2020-09-01 17:40:42
【问题描述】:

我有一个闪亮的应用程序,目前它接受用户输入并将其呈现为可下载的降价报告。我一直坚持让用户上传图像并让它在下载的报告上正确呈现。我知道如何将本地保存的图像嵌入到降价报告中,但是上传的图像呢?用户是否也可以上传多张图像进行渲染?我基本上只需要指出正确的方向,因为我无法找到任何关于这是否可能的信息。

【问题讨论】:

    标签: r shiny r-markdown markdown shiny-reactivity


    【解决方案1】:

    没有代表很难回答您的问题,但我假设您按照此处的说明将此设置作为参数化报告。 https://shiny.rstudio.com/articles/generating-reports.html

    我建议将此图像设置为传递给 r markdown YAML 标头的参数,如下所示。

    在您的应用中 somepicture 将被添加到参数中。

        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 = 'somepicture')
    
            # 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())
            )
          }
        )
      }
    )
    

    在您的降价中确保它包含在 YAML 标头中并使用 params$somepicture 调用它

    如下所示,抱歉,我不知道在我头顶的降价中使用的功能。

    ---
    title: "Dynamic report"
    output: html_document
    params:
      n: NA
    ---
    
    ```{r}
    some_function_to_add_a_picture(params$n)
    
    
    

    【讨论】:

      猜你喜欢
      • 2016-06-18
      • 2018-04-03
      • 2018-04-05
      • 2021-11-22
      • 2015-10-17
      • 2019-03-04
      • 1970-01-01
      • 1970-01-01
      • 2022-12-09
      相关资源
      最近更新 更多