Zer*_*ack 7 r observable shiny dt
我有一个闪亮的应用程序,它有一个 DT::renderDataTable,用户可以在数据表中选择一行。
以下代码将仅打印 FALSE(当选择一行时):
observeEvent(input$segment_library_datatable_rows_selected, {
print(is.null(input$segment_library_datatable_rows_selected))
})
Run Code Online (Sandbox Code Playgroud)
当一行也被取消选择时,如何打印它?(打印值将为 TRUE)
小智 15
observeEvent(input$selected,ignoreNULL = FALSE,{...})
Run Code Online (Sandbox Code Playgroud)
ignoreNULL
默认为TRUE
. 设置为FALSE
在取消选择时观察事件。
据我了解,一个工作的最小示例如下(如果选择了sel()
一行,则反应为 TRUE ):datatable
library(shiny)
library(DT)
ui <- fluidPage(
DT::dataTableOutput("datatable"),
textOutput("any_rows_selected")
)
server <- function(input, output) {
# Output iris dataset
output$datatable <- DT::renderDataTable(iris, selection = "single")
# Reactive function to determine if a row is selected
sel <- reactive({!is.null(input$datatable_rows_selected)})
# Output result of reactive function sel
output$any_rows_selected <- renderText({
paste("Any rows selected: ", sel())
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)