下载在R Shiny应用中生成的文件
我目前正在尝试生成一个闪亮的应用程序,该应用在按钮的印刷下生成并为用户下载数据。我有一个用户定义的函数,该功能从某些地方,分析并创建了由许多表组成的.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论