Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据radioButton下载csv或excel_R_Shiny_Shiny Reactivity - Fatal编程技术网

根据radioButton下载csv或excel

根据radioButton下载csv或excel,r,shiny,shiny-reactivity,R,Shiny,Shiny Reactivity,根据用户输入以excel或csv格式下载。该代码仅适用于单选按钮中的预选值。如下所示,它适用于csv,因为selected=“csv”。如果更改为xlsx,则仅适用于xlsx。用户应该能够选择,并且这两个选项都应该是可能的 可能值被缓存了,我需要以某种方式强制更新 library(shiny) ui <- fluidPage( h4("Download data"), wellPanel( fluidRow( column(4, r

根据用户输入以excel或csv格式下载。该代码仅适用于单选按钮中的预选值。如下所示,它适用于csv,因为
selected=“csv”
。如果更改为xlsx,则仅适用于xlsx。用户应该能够选择,并且这两个选项都应该是可能的

可能值被缓存了,我需要以某种方式强制更新

library(shiny)

ui <- fluidPage(
    h4("Download data"),
    wellPanel(
        fluidRow(
            column(4, radioButtons("dl_data_file_type", "Format",
                                   choices = c(excel = "xlsx",
                                               csv = "csv"),
                                   selected = "csv")),
            column(5),
            column(3, downloadButton("dl_data_dwnld_bttn"))
        )))


server <- function(input, output) {
    output$dl_data_dwnld_bttn <- {
        downloadHandler(
            filename = stringr::str_c(Sys.Date(), " Palim.", input$dl_data_file_type),
            content = function(file){
                x <- iris

                if ( input$dl_data_file_type == "xlsx")  {
                    writexl::write_xlsx(x, file)}
                else if ( input$dl_data_file_type == "csv") {
                    readr::write_csv(x, file)}

            })}}


shinyApp(ui = ui, server = server)
库(闪亮)

ui您在
filename
参数中使用的是被动值。在这种情况下,您必须将
filename
设置为一个函数:

filename = function(){
  stringr::str_c(Sys.Date(), " Palim.", input$dl_data_file_type)
}

filename
参数中使用的是被动值。在这种情况下,您必须将
filename
设置为一个函数:

filename = function(){
  stringr::str_c(Sys.Date(), " Palim.", input$dl_data_file_type)
}

你确定?我没有看到任何错误。没有,我没有试过。我想我现在明白了。看看我的答案,你确定吗?我没有看到任何错误。没有,我没有试过。我想我现在明白了。看看我的答案。