'R Shiny click on table field

I am currently learning R. I have a small project where a timetable is displayed and the user has the option to enter a subject.

After adding the subject to the timetable, it should be possible to click on it to open the modalDialog. Unfortunately my code does not work. I have tried it here:

observeEvent(input$mytable_cells_selected, {
    showModal(modalDialog(
      title = "Somewhat important message",
      "This is a somewhat important message.",
      easyClose = TRUE,
      footer = NULL))
  })

Can someone help me and tell where my error is?

ui <- fluidPage(
    theme = bs_theme(version = 4, bootswatch = "minty"),
      titlePanel(h1("My timetable", align = "center" )),
      sidebarLayout(
        position = c("left"),
        sidebarPanel(
          width = 4,
          selectInput("select1", label = h5("Event:"),
                      choices = c("math" , "sience", "sport") ,
                      selected = 1,
                      width = 400),
          actionButton("action", label = "Add")),
        mainPanel(
          width = 8,
          tableOutput('mytable')),
      ),
    )

and server:

server <- function(input, output, session) {
  
  timetable <- reactiveVal(
    data.frame(monday = c("","","","",""),
               tuesday = c("","","","",""),
               wednesday = c("","","","",""),
               thursday = c("","","","",""),
               friday = c("","","","",""))
  )
   
  output$mytable <- renderTable(timetable(), 
          bordered = TRUE, 
          spacing = c('l'), 
          width = "100%",
          striped = TRUE,
          align = 'c',
          rownames = TRUE,
          selection = list(target = 'cell'))
  
  observeEvent(input$action, { 
    tmp <- timetable()
    tmp[1, "monday"] <- input$select1
    timetable(tmp)
  })

  observeEvent(input$mytable_cells_selected, {
      showModal(modalDialog(
         title = "message",
         "This is a somewhat important message.",
         easyClose = TRUE,
         footer = NULL))
})
}

shinyApp(ui, server)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source