将 r shiny observeEvent 与 downloadHandler 一起使用

Using r shiny observeEvent with a downloadHandler

我对使用观察者观察创建 CSV 文件以供下载的操作的过程提出了挑战。我认为 R-Studio 文档指出 eventExpr 可能是 "complex expression inside curly braces." Is this a valid eventExpression?我使用这个构造 5 次,当我的 shinyApp 启动时,所有五个条件都被触发。

    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

有什么想法或建议吗?

如您所述,所有五个都在启动时被调用。该代码未绑定到输入 $ 或其他更改,因此它只是 运行s 并且它报告它 已启动 。考虑是要它在下载完成后报告,还是要 运行 用户输入的代码。

我通过将日志函数调用添加为 downloadHandler 的内容函数的第一个子句来完成添加 activity 日志操作。调用 logUse("WC_Download") 按要求运行,activity 日志被适当扩充。

    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