下载在R Shiny应用中生成的文件

发布于 2025-01-28 11:31:20 字数 1790 浏览 4 评论 0原文

我目前正在尝试生成一个闪亮的应用程序,该应用在按钮的印刷下生成并为用户下载数据。我有一个用户定义的函数,该功能从某些地方,分析并创建了由许多表组成的.CSV。

我遇到的瓶颈成功地将此.csv文件包含在多个表中,并允许它轻松下载。我已经尝试应用在此处介绍的解决方案,但是当我运行应用程序脚本时,数据中的数据是从按钮生成的,但并没有像我希望的那样列出下载窗口。有没有一种方法可以使用下载Handler并将其链接到下载button下载link功能之外的其他方法?

当前UI功能:

ui <- dashboardPage(
  dashboardHeader(title = "Download Center"),
  dashboardSidebar(
    sidebarMenu(id="mytabs",
                sidebarMenuOutput("menu")
    )
  ),
  dashboardBody(tabItems(
    
  tabItem(tabName = "DataHarah", h2("Download Your Data Here"),
                  textInput(inputId='startyear', label='What is the first year?'
                            ,value=2021, width = NULL, placeholder = "Inputs should be
                            a four digit year (e.g. 2022)."),
          textInput(inputId='endyear', label='What is the last year?'
                    ,value=2022, width = NULL, placeholder = "Inputs should be
                            a four digit year (e.g. 2022)."),
          actionButton("do", "Generate & Download Your Data!")      
                 ))
  ))

当前服务器功能&amp;初始化:

observeEvent(input$do,
               {DataTalk(input$startyear,input$endyear) # function that generates a csv file
                                                        # containing multiple tables.
                 
                 output$downloadData <- downloadHandler(  #download handler that may not be connected properly.
                   filename = c('mycsv.csv'),
                   content = function(file){
                     file.copy('mycsv.csv',file)})})}
shinyApp(ui, server)

I am currently trying to generate a Shiny App that at the press of a button generates and downloads data for a user. I have a user defined function that pulls data from some places, analyzes, and creates a .csv comprised of numerous tables.

The bottleneck I'm running into is successfully taking this .csv file comprised of multiple tables and allowing it to be easily downloaded. I have tried applying the solution presented here, but when I run the application script, all of the data is generated from the button but it doesn't bring up the download window as I'd hoped. Is there a way of using downloadHandler and link it to something other than a downloadButton or downloadLink function?

Current UI Function:

ui <- dashboardPage(
  dashboardHeader(title = "Download Center"),
  dashboardSidebar(
    sidebarMenu(id="mytabs",
                sidebarMenuOutput("menu")
    )
  ),
  dashboardBody(tabItems(
    
  tabItem(tabName = "DataHarah", h2("Download Your Data Here"),
                  textInput(inputId='startyear', label='What is the first year?'
                            ,value=2021, width = NULL, placeholder = "Inputs should be
                            a four digit year (e.g. 2022)."),
          textInput(inputId='endyear', label='What is the last year?'
                    ,value=2022, width = NULL, placeholder = "Inputs should be
                            a four digit year (e.g. 2022)."),
          actionButton("do", "Generate & Download Your Data!")      
                 ))
  ))

Current Server Function & Initialization:

observeEvent(input$do,
               {DataTalk(input$startyear,input$endyear) # function that generates a csv file
                                                        # containing multiple tables.
                 
                 output$downloadData <- downloadHandler(  #download handler that may not be connected properly.
                   filename = c('mycsv.csv'),
                   content = function(file){
                     file.copy('mycsv.csv',file)})})}
shinyApp(ui, server)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文