Shiny (R): Download selection in selectInput to local machine -
i trying create shiny app users can view list of files in directory, select 1 of files, , download computer. may over-complicating this, can't seem find solution.
ui.r
filenames <- list.files(path=".",pattern="\\.txt") shinyui(navbarpage("download page", tabpanel("download", sidebarlayout( sidebarpanel( selectinput("filenames", "select file want download:", filenames), downloadbutton('downloaddata', 'download') ), mainpanel( p("preview of sheet."), tableoutput('table') ))))) server.r
library(shiny) shinyserver(function(input, output) { datasetinput <- reactive({ switch(input$filenames, filenames) }) output$table <- rendertable({ datasetinput() }) output$downloaddata <- downloadhandler( filename = function() { paste(input$dataset, '.csv', sep='') }, content = function(file) { write.csv(datasetinput(), file) } )}) when run app, can view list of files in directory, download function not result in selected file being downloaded.
assuming bunch of 'csv' files in working directory code below list , preview 'csv' files , download selected file desired directory.
ui.r
shinyui(navbarpage("download page", tabpanel("download", sidebarlayout( sidebarpanel( selectinput("filenames", "select file want download:", list.files(pattern = '.csv')), downloadbutton('downloaddata', 'download')), mainpanel( p("preview of sheet."), tableoutput('table') ))))) server.r
library(shiny) shinyserver(function(input, output) { datasetinput <- reactive({ switch(input$filenames, filenames) }) output$table <- rendertable({ read.csv(input$filenames, header=true) }) output$downloaddata <- downloadhandler( filename = function() {input$filenames}, content = function(file) {write.csv(read.csv(input$filenames, header=true),file)} )})
Comments
Post a Comment