I would like to display a modal when the user launches the app. To do so, I used this answer. However, when clicking on the button supposed to close the modal, I have the error:
Warning: Error in : $ operator is invalid for atomic vectors
Apparently, this error is due to something in observeEvent but I can't figure out what the error is. How can I solve this?
Reproducible example:
library(shiny)
library(shinyBS)
popup <- bsModalNoClose("window", "Window",
                        title="Click 'Choice 1' to close the popup", size='small',
                        actionButton('choice1', 'Choice 1', class = 'btn action-button btn-success'),
                        actionButton('choice2', 'Choice 2', class = 'btn action-button btn-success'),
                        tags$head(tags$style("#window .modal-footer{display:none}
                                       .modal-header"),
                                  tags$script("$(document).ready(function(){
                                        $('#window').modal();
                                        });")
                        ))
ui <- shinyUI(fluidPage(
  popup
))
server <- shinyServer(function(input, output, session) {
  observeEvent(input$choice1, {
    toggleModal(session = "session",
                modalId = "window",
                toggle = "close")
  })
})
shinyApp(ui, server)