ConditionalPanel based on DT:Datatable select in shiny-modules

I have a problem with convert my shiny app to use Shiny Modules. In my app I have a ConditionalPanel where conditional is a js-string to DT:datatable_rows_selected. I don't understand how I need to rewrite this condition to work with ShinyModule conception.

Example: This is work correct (when select rows in table - ConditionalPanel is open):

library(shiny)
library(DT)
shinyApp(
  ui = fluidPage(
    DT::dataTableOutput("testTable"),
    conditionalPanel(condition = "typeof input.testTable_rows_selected  !== 'undefined' && input.testTable_rows_selected.length > 0",
                     verbatimTextOutput("two")                     
                     )
  ),
  server = function(input,output) {
    output$testTable <- DT::renderDataTable(mtcars, selection=list(mode="multiple",target="row"))
    output$two <- renderPrint(input$testTable_rows_selected) 
  }
)

But this is not work:

library(shiny)
library(DT)
testUI <- function(id) {
ns <- NS(id)
table_id = ns("testTable")
tagList(
DT::dataTableOutput(table_id),
conditionalPanel(condition = paste0("typeof input.",table_id,"_rows_selected !== 'undefined' && input.",table_id,"_rows_selected.length > 0"),
verbatimTextOutput(ns("two"))
)
)
}

test <- function(input,output,session) {
ns <- session$ns
output$testTable <- DT::renderDataTable(mtcars, selection=list(mode="multiple",target="row"))
output$two <- renderPrint(input$testTable_rows_selected)
}

shinyApp(
ui = testUI("one"),
server = function(input,output) {
out <- callModule(test,"one")
}
)

This is correct working example. There is not need to touch js-string of conditional. Just set ns parameter in ConditionalPanel

library(shiny)
library(DT)


testUI <- function(id) {
  
  ns <- NS(id)

  tagList(
      fluidPage(
        DT::dataTableOutput(ns("one")),
        conditionalPanel( 
                          condition = "typeof input.one_rows_selected  !== 'undefined' && input.one_rows_selected.length > 0", 
                          ns=ns, 
                          verbatimTextOutput(ns("two"))
                         )
    )
  )
}

test <- function(input,output,session) 
{
  output$one <- DT::renderDataTable(mtcars, selection=list(mode="multiple",target="row"))
  output$two <- renderPrint(input$one_rows_selected) 
}

shinyApp(
  ui = testUI("p"),
  server = function(input,output,session) {  out <- callModule(test,"p")}
)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.