如何使用 python 网状闪亮的下载按钮?

How to use Download Button in shiny with python reticulate?

我正在构建一个闪亮的应用程序并且我有一个 "download button"!我还使用了 reticulate 中的 python,因为我有一个脚本可以根据应用程序中生成的图表为我生成 PDF。我用来创建 pdf 的包是 FPDF

这是我在 python 中创建 pdf 的 R 函数

createPdf <- function(path){
     source_python("plots/create_pdf.py")
       pdf <- PDF()
       pdf$alias_nb_pages()
       pdf$add_page()
       pdf$plot_charts_field('farmer', 'region', 'produto')
       pdf$output(path + 'report.pdf', 'F')
   }

这是我的下载按钮输出

output$download <- downloadHandler(
     filename = 'report.pdf',
     content = function(file) {
      createPdf (file)
     })

当我调用该函数时 "createPdf" 我需要在参数中传递 pdf 将下载的路径,用户将选择目录,但我不知道该怎么做。有可能这样做吗?我该怎么做?

我的问题是我需要将保存 pdf 的路径传递给 python 脚本。这是我对问题的解决方案:

ui.R

sidebarLayout
  (
    sidebarPanel(width = 3,
      radioButtons(inputId = "choices", "Tipo", c("Individual", "Global"), selected = "Individual"),
      uiOutput("Filters"), downloadButton('download', "Download")
    )

server.R

  makePdf <- function(filename){
     source_python("plots/create_pdf.py")
     if (input$choices == 'Individual')
     {
       pdf <- PDF()
       pdf$alias_nb_pages()
       pdf$add_page()
       pdf$plot_charts_field('farmer', 'region', 'produto')
       pdf$output(filename, 'F')
     } else
     {
       source_python("plots/plot_mapa.py")
       plot_mapa(alltables_filter())
       pdf <- PDF()
       pdf$alias_nb_pages()
       pdf$add_page()
       pdf$plot_charts_global()
       pdf$output(filename, 'F')
     }
   }


output$download <- downloadHandler('report.pdf', function(theFile) {

       makePdf(theFile)

     })

这样用户就可以下载pdf了