我有以下应用程序:
beta
当我保存静态数据集(例如...
selectInput("cars", "Pick a Car: ",
c("All" = "All Cars",
"Ford" = "Ford",
"Volvo" = "Volvo",
"Ferrari" = "Ferrari",
"Fiat" = "Fiat",
"Merc" = "Merc"))
)),
shinySaveButton("save", "Save file", "Save file as ...", filetype=list(csv="csv")),
DT::dataTableOutput('table1')
)
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
mtcars$car <- rownames(mtcars)
output$table1 <-renderDataTable({
mtcars %>%
filter(stringr::str_detect(car, as.character(input$cars)) | input$cars == 'All Cars')
})
observe({
volumes <- c("UserFolder"="~/Documents/R1/DwnLdWord/saves")
shinyFileSave(input, "save", roots=volumes, session=session)
fileinfo <- parseSavePath(volumes, input$save)
data <- input$table1_rows_all
if (nrow(fileinfo) > 0) {
write.csv(data, fileinfo$datapath)
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
或iris
)时,文件将保存实际数据。但是,从图像中可以看出,我想保存过滤后的DT的内容。
我认为这就是input$tableid_rows_all的用途,但是我只能得到随机的整数/数值。我一直对这种胡说八道感到麻烦,但是我真的很想让它工作,因为它是如此有价值的功能。
帮助?
答案 0 :(得分:1)
检查:
server <- function(input, output, session) {
mtcars$car <- rownames(mtcars)
output$table1 <-renderDataTable({
mtcars %>%
filter(stringr::str_detect(car, as.character(input$cars)) | input$cars == 'All Cars')
})
observe({
volumes <- c("UserFolder"="~/Documents/R1/DwnLdWord/saves")
shinyFileSave(input, "save", roots=volumes, session=session)
fileinfo <- parseSavePath(volumes, input$save)
data <- mtcars[input$table1_rows_selected,]
if (nrow(fileinfo) > 0) {
write.csv(data, fileinfo$datapath)
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
rows_selectd
是因为rows_all
会退还表中的所有rows
tableId
代替table1
mtcars[input$table1_rows_selected,]
我希望这可以帮到您。 最好!