gpt4 book ai didi

r - 如何在 shiny 中创建一个简单的下拉菜单?

转载 作者:行者123 更新时间:2023-12-05 03:54:23 25 4
gpt4 key购买 nike

因此,在我 Shiny 的应用程序的 tabsetpanel 内的三个选项卡面板中,我有三个下载按钮。有什么办法我不能创建下拉菜单而不是这些选项卡面板?我不想弄乱输出,只是以下拉菜单而不是选项卡面板的形式组织下面的代码。

tabsetPanel(tabPanel("download 1", downloadBttn("downloadData",size="sm","Download1"),tabPanel("download 2",downloadBttn("downloadData",size="sm","Download2"),tabPanel("download 3",downloadBttn("downloadData",size="sm","Download3"))

最佳答案

使用选择输入,以便用户只需从下拉框中选择要下载的数据。无需单独的选项卡即可下载数据

library(shiny)

ui <- fluidPage(
selectInput("download", "Select Data to download", choices = c("euro", "mtcars", "iris")),
downloadButton("downloadData")
)

server <- function(input, output, session) {

dataDownload <- reactive({
switch(input$download,
"euro" = euro,
"mtcars" = mtcars,
"iris" = iris)
})

output$downloadData <- downloadHandler(
filename = function() {
paste(input$download, ".csv", sep = "")
},
content = function(file) {
write.csv(dataDownload(), file, row.names = FALSE)
}
)

}

shinyApp(ui, server)

关于r - 如何在 shiny 中创建一个简单的下拉菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61044496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com