根据radioButton下载csv或excel
根据用户输入以excel或csv格式下载。该代码仅适用于单选按钮中的预选值。如下所示,它适用于csv,因为根据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
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)
}
你确定?我没有看到任何错误。没有,我没有试过。我想我现在明白了。看看我的答案,你确定吗?我没有看到任何错误。没有,我没有试过。我想我现在明白了。看看我的答案。