R shiny observe for row deselection dataTable

r shiny datatable select rows
r shiny table example
reactive datatable shiny
r shiny clickable table
r datatable formatstyle
shiny | editable table
datatableproxy
r shiny filter data table

I have a shiny app that has a DT::renderDataTable, the user can select a row in the datatable.

The following bit of code will only print FALSE (when a row is selected):

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

How do I get it to print when a row is also deselected? (The print value would be TRUE)

As I understand a working minimal example would be the following (sel() reactive is TRUE if a row in datatable is selected):

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)

observeEvent not fired with datatable (DT) deselection : rshiny, observeEvent not fired with datatable (DT) deselection. Hello, I'm fairly new to shiny,. I'm trying to figure out how I can get the event from a deselection of a row in  Shiny's reactive programming framework is primarily designed for calculated values (reactive expressions) and side-effect-causing actions (observers) that respond to any of their inputs changing. That's often what is desired in Shiny apps, but not always: sometimes you want to wait for a specific action to be taken from the user, like clicking an actionButton() , before calculating an expression or taking an action.

Alternatively you can use observe() which will respond to any hits to the input$datatable_rows_selected, including NULL.

To repurpose Kristoffer W. B.'s code:

library(shiny)
library(DT)
ui <- fluidPage(
  DT::dataTableOutput("testtable")
)

server <- function(input, output) {
  # Output iris dataset
  output$testtable<- DT::renderDataTable(iris, selection = "single")


  # Observe function that will run on NULL values
  an_observe_func = observe(suspended=T, {
                    input$testtable_rows_selected
                    isolate({
                      #do stuff here
                      print(input$testtable_rows_selected)
                      })
                    })

  #start the observer, without "suspended=T" the observer 
  #  will start on init instead of when needed
  an_observe_func$resume()

shinyApp(ui, server)

A few things to note:

1) I found it best to start the observer in suspended mode, that way it doesn't start when the program initializes. You can turn it on whenever you want it to... observe... (such as after you render the datatable, or before you'd like to start tracking selections).

2) Use isolate to stop the observer from tracking multiple elements. in this case the observer should only react to input$testtable_rows_selected, instead of everything else occurring. The symptom of this problem is that your observer fires multiple times on a single change.

Using DT in Shiny, Here is a minimal example of (client-side) DataTables in Shiny using the convenience functions Clicking on the table body will select/deselect rows. Shiny (>= v1.10.2) currently uses DataTables v1.10. If you have used DataTables in Shiny before (specifically, before Shiny v0.10.2), you may need to change some parameter names for your DataTables, because Shiny (<= v0.10.1) was using DataTables v1.9, and DataTables v1.10 has changed the parameter names.

observeEvent(input$selected,ignoreNULL = FALSE,{...})

ignoreNULL is defaulted to TRUE. Set to FALSE to have the event observed upon deselection.

row selection event not generated if proxy is called early · Issue , I used the selected rows of a DT to trigger other reactive a lot, and sometimes I need If we comment out the proxy selection line in renderDT, everything is normal options(shiny.trace = TRUE) library(shiny) library(DT) ui <- fluidPage( output$table <- renderDT({ dt_table <- DT::datatable(data.frame(iris))  Shiny combines the computational power of R with the interactivity of the modern web. Get Started See Gallery. Here is a Shiny app. Shiny apps are easy to write. No web development skills are required. Shiny comes with a variety of built in input widgets. With minimal syntax it is possible to include widgets like the ones shown on the left in

Select rows with same values in two columns in datatable (DT), Hello All, I have an app in which the user can select multiple rows of a data The problems are that it's not possible to deselect rows and when filters are library(​shiny) library(DT) library(dplyr) library(data.table) shinyApp( ui updating drop-​down lists #### observe({ updateSelectInput(session, "cyl","cyl",  I have a dataframe which I want to filter and create tables based on years in this case. I have 4 years now.So I would like to create 4 new tables and show them seperately on the shiny app.I do get the part of looping an&hellip;

Programmatically update row selection (or other attributes) of , Is there any way to update the selected or expanded row in a reactable package or through injecting javascript directly into my shiny application? desired functionality as it can be done in the DT package with datatables. c(1, 3​, 5)) }) observeEvent(input$clear_btn, { # Clear row selection using NA or  This tutorial describes how to make a DataTable as shown below in Shiny with Add, Edit, Copy and Delete functionality. Entries are stored in a local SQL database which makes it possible to retrieve the data between sessions.

Editable DataTables in R shiny using SQL, This tutorial describes how to make a DataTable as shown below in Shiny with Function to observe if all mandatory fields are filled out. showing the form module the row is deselected which results in a NULL when the  2.1 Selecting Rows/Columns/Cells. You may select rows, columns, or cells in the table, and obtain the indices of the selected objects. See this Shiny app for a comprehensive example (you can find its source code under system.file('examples', 'DT-selection', package = 'DT')).

Comments
  • I guess observeEvent does not trigger when input$segment_library_datatable_rows_selected is NULL. Have you tried a standard observe or reactive function (e.g. sel <- reactive({is.null(input$segment_library_datatable_rows_selected)})). Also please specify if your DT has selection of multiple rows enabled and if you want to detect any changes in the row selection (e.g. also going from 3 to 2 selected rows).
  • @KristofferWintherBalling DT selection is set to single, and the above works perfectly.
  • have you tried simply: print(!is.null(input$segment_library_datatable_rows_selected))