我为R Shiny应用程序创建了一个下载按钮,用于输出CSV . 我想在UI中添加复选框,以获取输出json,xls和TSV文件的选项,然后输出服务器函数中的相应函数 . 任何见解?贝娄是一些与此相关的最小代码:
library(shiny)
set.seed(123)
N<- 500
M<-56
EF<- matrix( rnorm(N*M,mean=23,sd=3), N, M)
WM<- matrix( rnorm(N*M,mean=20,sd=3), N, M)
DP<- matrix( rnorm(N*M,mean=25,sd=3), N, M)
Date <- seq(as.Date("2018-01-01"), as.Date("2018-02-25"), by="days")
Date <- as.POSIXct(Date, format = "%Y-%m-%d %H:%M")
ui <- fluidPage(
titlePanel(code(strong("Measures"), style = "color:black")),
sidebarLayout(
sidebarPanel(
strong("Tools:"),
selectInput("Test",
label = "Choose a measure to display",
choices = c("EF",
"WM",
"DP"
),
selected = "EF"),
downloadButton("downloadData", "Download")),
mainPanel(
code(strong("Output Data"))
))
)
server <- function(input, output) {
output$downloadData <- downloadHandler(
filename = function() {
paste(input$dataset, "Table.csv", sep = ",")
},
content = function(file) {
write.csv(x, file, row.names = FALSE)
}
)
}
# Run that shit ----
shinyApp(ui = ui, server = server)
1 回答
不是最优雅的,但是这里's an option. I created a mock example -- I couldn' t使用你的代码,因为
x
(在你的例子中定义的是're downloading) isn't) .