[英]Why is input$tableid_all_rows (DT) working in Shiny?
我有以下應用程序:
...
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
或mtcars
)時,文件會保存實際數據。 但是,從圖片中可以看出,我想保存過濾后的 DT 的內容。
我認為這就是input$tableid_rows_all 的用途,但我只得到隨機整數/數字值。 我一直對這種廢話感到困擾,但我真的很想讓它工作,因為它是如此有價值的功能。
幫助?
檢查這個:
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,]
我希望這對你有用。 最好的事物!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.