Search code examples
rshinyobservers

Using r shiny observeEvent with a downloadHandler


I am challenged by the process of using an observer to observe the action of creating a CSV file for download. I think that the R-Studio documentation states that eventExpr may be a "complex expression inside curly braces." Is this a valid eventExpression? I am using this construct 5 times, and all five conditions are triggered when my shinyApp initiates.

    observeEvent(
        {
        ### Observe the download handler preparing for CSV download
        output$Wire_Centers.csv <- downloadHandler(
            filename = "Wire_Centers.csv",
            content = function(file) {
                write.table(WC_List_2(), file, row.names=FALSE, col.names = TRUE, sep=',') ### end write.table
                } # End content function
            ) # End downloadHandler
            }, { # End observered event, start log
        logUse("WC_Download")
        }) # end observeEvent output condition

Any ideas or suggestions?


Solution

  • I accomplished adding the activity log action by adding the log function call as the first clause of the content function for the downloadHandler. The call logUse("WC_Download") operates as required, and the activity log is appropriately augmented.

        output$Wire_Centers.csv <- downloadHandler(
            filename = "Wire_Centers.csv",
            content = function(file) {
                logUse("WC_Download")
                write.table(WC_List_2(), file, row.names=FALSE, col.names = TRUE, sep=',') ### end write.table
                }, # End content function
            ) # End downloadHandler