2017-03-13 44 views
0

我有一個閃亮的應用程序有一個DT :: renderDataTable,用戶可以選擇數據表中的一行。R閃亮觀察行取消數據表

(當選擇行)下面的代碼位將只打印FALSE:

observeEvent(input$segment_library_datatable_rows_selected, { 
    print(is.null(input$segment_library_datatable_rows_selected)) 
}) 

如何獲得它打印一行時也取消? (打印值將是TRUE)

+0

我想'observeEvent'不當'input $ segment_library_datatable_rows_selected'爲'NULL'時觸發。您是否嘗試了標準觀察或反應函數(例如'sel < - reactive({is.null(input $ segment_library_datatable_rows_selected)})')。還請指定您的DT是否選擇了多行啓用,以及是否要檢測行選擇中的任何更改(例如也從3到2個選定行)。 –

+0

@KristofferWintherBalling DT選擇設置爲單一,上述工作完美。 – ZeroStack

+0

您是否嘗試過:'print(!is.null(input $ segment_library_datatable_rows_selected))' –

回答

1

據我所知一個工作最小的例子是下面的(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)