Using the input from updateSelectizeInput()

I have made a updateSelectizeInput function in my server.R

 selectedData <- reactiveValues()
  
  observeEvent(input$season, {
    if(input$season == 1718) {
      
      player_name <- pbp_1718 %>%
        # Check for NAs
        filter(!is.na(coords_x),
               !is.na(coords_y),
               !is.na(event_rinkside),
               !is.na(event_player_1)) %>% 
        pull(event_player_1) %>% 
        unique()
      
      player_name_title <- player_name %>% 
        str_replace_all("\\.", " ") %>% 
        str_to_title()
      
      # Create title case names since choices argument says:
      # If elements of the list are named, then that name rather than the value is displayed to the user. 
      names(player_name) <- player_name_title
      selectedData <- player_name
    } else {
      
      player_name <- pbp_1819 %>%
        # Check for NAs
        filter(!is.na(coords_x),
               !is.na(coords_y),
               !is.na(event_rinkside),
               !is.na(event_player_1)) %>% 
        pull(event_player_1) %>% 
        unique()
      
      player_name_title <- player_name %>% 
        str_replace_all("\\.", " ") %>% 
        str_to_title()
      
      # Create title case names since choices argument says:
      # If elements of the list are named, then that name rather than the value is displayed to the user. 
      names(player_name) <- player_name_title
      
      selectedData <- player_name
      
    }
    
    updateSelectizeInput(session, "player_shot",
                         choices = names(selectedData),
                         server = TRUE)
    
    
  })

I hope my explanation takes place of a reproducible example.

Basically, users can select a season (1718 or 1819) and then according to the season, users see different groups of players inside selectizeInput .

The problem I have is using the user's selection (input$player_shot) in another plot located in the server. In my plot, I call input$player_shot but it doesn't seem to be working...

If this explanation is lacking, I'll def post part of my entire script (Its 1000 lines long!)

To double check what is available, I usually add a str(input). This can be done just inside your observeEvent(input$season, {....

Taking a stab in the dark...

  • If the input value input$player_shot can be seen in the SAME application, but not at this line of code, I am guessing either input$player_shot or this observeEvent code is inside a module.

To remedy this, I suggest making a reactiveVal in the main code area and pass it into both the observeEvent and the input$player_shot code sections. If the player_shot code needs to notify the observeEvent code, the reactiveVal passed in should be updated and regular shiny interactions will take effect inside the observeEvent code. If the reactiveVal item needs to be a trigger as well, make a list for the input of observeEvent (observeEvent(list(input$season, input$player_shot_val), {...).

I hope this lays out a framework to use. Please let me know if I missed the mark!

This topic was automatically closed 54 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.