Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R DataTable disable highlighting row on cklick

I have a datatable in a shiny web app.
However, the default setting for datatable is that a line is highlighted in blue if it is clicked.
I would like to disable this option. It should no longer be highlighted in color.

This problem has already been discussed here a few years ago:
R Shiny DataTable selected row color

Apparently, however, the css / javascript command has changed. Now, it seems to be box-shadow:
https://datatables.net/forums/discussion/comment/208770

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

However, I do not get this new option implemented in my example.
Can anyone help me?

enter image description here

Here is my reproducible example:

library(ggplot2)
library(shiny)

ui <- fluidPage(
  titlePanel("Basic DataTable"),
  
  fluidRow(
    column(4,
           selectInput("man",
                       "Manufacturer:",
                       c("All",
                         unique(as.character(mpg$manufacturer))))
    ),
    column(4,
           selectInput("trans",
                       "Transmission:",
                       c("All",
                         unique(as.character(mpg$trans))))
    ),
    column(4,
           selectInput("cyl",
                       "Cylinders:",
                       c("All",
                         unique(as.character(mpg$cyl))))
    )
  ),
  DT::dataTableOutput("table")
)

server <- function(input, output) {
  
  output$table <- DT::renderDataTable(DT::datatable({
    data <- mpg
    if (input$man != "All") {
      data <- data[data$manufacturer == input$man,]
    }
    if (input$cyl != "All") {
      data <- data[data$cyl == input$cyl,]
    }
    if (input$trans != "All") {
      data <- data[data$trans == input$trans,]
    }
    data
  }))
  
}

shinyApp(ui = ui, server = server)

>Solution :

You can disable row clicking using selection = "none" in DT::renderDataTable.

library(ggplot2)
library(shiny)

ui <- fluidPage(
  titlePanel("Basic DataTable"),
  DT::dataTableOutput("table")
)

server <- function(input, output) {
  
  output$table <- DT::renderDataTable({
    mpg
  }, selection = "none")
  
}

shinyApp(ui = ui, server = server)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading