download Handler

I have an R code, which process the dataframe and get result in excel. But some have I could see Download function is not working properly.

Intially I selected data which does not have "DATE" column ,palced in the dataframe and downloaded it.
After that I'll add a column name "DATE" and will download it again.

But the problem lies here, somehow I'm getting "DATE" column in the 'dfOutput'. How can I resolve this?
and my second question is, how can I add sheet to the write_xlsx file?

dfOutput <-  sqldf("select dfOutput.* from dfOutput")

    output$loadOutput <- downloadHandler(
      filename = function(){ ("dfOutput.xlsx")},
      content = function(file){ write_xlsx(dfOutput, path = file)}
    dfOutput$Date <- dtDate

dfOutputDate <-  sqldf("select dfOutput.* from dfOutputDate")

output$loadOutputDate <- downloadHandler(
      filename = function(){ ("dfOutputDate.xlsx")},
      content = function(file){ write_xlsx(dfOutputDate, path = file)}

These don't appear to be reactive expressions so you should expect them to be static during the runtime of the application. because they will only run once when the server code of the app is executed.

assuming you are using writexl library, I dont believe it supports adding sheets to existing workbooks (other libraries can) but it lets you write a new workbook with multiple sheets, like in this 2 sheet example


 write_xlsx(list(iris_sheet = iris,
                       mtcars_sheet = mtcars),

Is there any way, I can make it dynamic?

Search for the online textbook Mastering Shiny and study the section on reactivity.

1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.