Home > database >  Error in get: object input$tableid_cell_clicked not found
Error in get: object input$tableid_cell_clicked not found

Time:07-02

I want to observe the cell_clicked event on one of my datatables. Normally I'd do it like this:

shiny::observeEvent(input$tableId_cell_clicked),{
  ...
}

The table I'm using now has a tableId that's stored in a variable. I'm trying the following:

shiny::observeEvent(get(paste0("input$", self$name, "_cell_clicked")), {
  ...
}

This gives me the following error:

Error in get: object 'input$Macrolaag_cell_clicked' not found

The creation happens like this:

#server side
output[[self$name]] <- DT::renderDataTable( ... )

#ui side
shiny::column(12, DT::dataTableOutput(self$name))

I don't understand why I'm getting this error. Can anyone help me?

CodePudding user response:

A fully working example:

library(DT)
library(shiny)
library(datasets)

ui <- fluidPage(
  DTOutput("iris_out")
)

server <- function(input, output, session) {
  output$iris_out<- renderDT({iris})
  
  table_name <- "iris_out"
  
  shiny::observeEvent({input[[paste0(table_name, "_cell_clicked")]]}, {
    clicked_input_id <- paste0(table_name, "_cell_clicked")
    # input[[clicked_input_id]] is the same as input$iris_out_cell_clicked
    cat("input_id:", clicked_input_id, "\n")
    print(input[[clicked_input_id]])
    })
}

shinyApp(ui, server)
  • Related