error in downloading files from r shiny app

This post was flagged by the community and is temporarily hidden.

hi @mahii I am getting the following error while running your app
Error in useShinyalert() : could not find function "useShinyalert"

Can you create a minimal app to showcase your issue?

1 Like

The file param to the function is not used in the code, rather some con variable that is undefined

 content = function(file) {
      write.csv(df1(), file)
    }
1 Like

thank you so much sir for the reply I got the solution sir..

thank you for ur response sir.

how can I download the results from multiple tabs using the single download button ?

id try to write multiple csv. zip them up, then copy the zip to where the file param says.
I think that should work.

no I need to download them separately not in combined way sir.. for ex. as I have 6 tabs and each tab giving one type of result and whenever I click on that tab and need to download the results from that tab only.. similar way among 6 tabs I need to download results from all tabs separately by using the single download button

    ```

server <- function(input, output, session){

 df1 <- eventReactive(input$action, {
  GC_content7(input$file$datapath)
  })
  
  output$res1 <- renderPrint({ 
    df1()
  })

 


output$downloadData <- downloadHandler(
    filename = function() {
      paste('input$res1', Sys.Date(), '.csv', sep='')
    },
    content = function(file) {      write.csv(df1(), file)    }
  )
 
 df5 <- eventReactive(input$action, {
  
  cgr_res(input$file$datapath)
  })
  
  output$res5 <- renderPlot({ 
    df5()
  })


 df6 <- eventReactive(input$action, {
  AMIP(input$file$datapath,input$num1,input$num2)
  
  })
  output$res6 <- renderPrint({
    df6()
  })
output$downloadData <- downloadHandler(
    filename = function() {
      paste('input$res6', Sys.Date(), '.csv', sep='')
    },
    content = function(file) {      write.csv(df6(), file)    }
  )

@nirgrahamuk @ginberg sir does the above mentioned method will work for me ?

UI items in shiny need unique names
you have one uI in sidebarpanel that you call downloadData,
but you define its server code twice. which would not work, the second would override the first.
you should provide your tabsetPanel in the ui with an id

id If provided, you can use input$ id in your server logic to determine which of the current tabs is active. The value will correspond to the value argument that is passed to tabPanel .

https://shiny.rstudio.com/reference/shiny/0.14/tabsetPanel.html

You would then use this in your single server definition for output$downloadData to decide what it should do based on the tab shown.

1 Like

Hello. Sorry to post on this thread (first post in the forum, and new to Shiny). I am trying to do exactly what you describe here, I am trying to write multiple csv files of processed data, and zip them up for downloadand. I have been struggling for about two weeks. Could you help? . The original uploaded data is in list s, and there are two types of data you cab download (stored in datasetInput).
Thank you!

output$downloadZip <- downloadHandler(
    filename = function(){
      paste("maldiprocresults",".zip")
    },
    content = function(con){
    tmpdir <- tempdir()
    setwd(tempdir())
    filestosave=c()
      for (i in 1:length(s)){
  	 x<-as.matrix(datasetInput()[[i]])
  	 f<-(paste("maldiprocres", names(s)[[i]], sep="_" ))
  	 filestosave=c(filestosave,write.csv(x,f))  	
 } 		
  	zip(zipfile=con, files=filestosave)
 	  },
     contentType = "application/zip"
  )

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.