samedi 30 janvier 2021

Why does RenderUI randomly kick an error from some selection of Selectinput?

I am trying to render some dynamic text in the ui.r based on a user selection from selectinput and it works for most names but there are one or two in the list that kick the error:

Warning: Error in FUN: argument is not a character vector
  99: lapply
  98: paste8
  97: HTML
  96: renderUI [/Users/spencepurnell/Documents/Shiny_apps/Ray_Lewis_Experiment/server.R#933]
  95: func
  82: origRenderFunc
  81: output$combine_compare_color
   1: runApp

Given that error message I suspect it has something to do with parse of the characters but again it works for other names in the list but two names specifically kick the error and it cascades.

Here is how I set up the ui:

tabItem("profile_tab",
                           fluidRow(
                             box(
                               selectInput("profile_player_selection", 
                                           "Select Player to Profile", 
                                           choices = as.list(ed_profile_names), 
                                           selected = "Anthony Nelson")
                             ),
                             box(
                               selectInput("player_profile_comparison",
                                           "Select Player to Compare",
                                           choices =  as.list(ed_profile_names_compare),
                                           selected = "Nick Bosa"))
                           ),
                           fluidRow(
                             box(title = uiOutput("combine_status_color"), 
                                 width = 6,
                                 collapsible = T,
                                 tableOutput("combine_page_table"),
                                 ),
                             box(title = uiOutput("combine_compare_color"),
                                 width = 6,
                                 collapsible = T,
                                 tableOutput("combine_page_comparison")
                                 )
                              )
                           ) 

And here is the server.r:

ed_color <- reactive({
      data_ed() %>% 
        dplyr::select(
          Name,
          "Height (in)",
          "Weight (lbs)",
          "40 Yard",
          "Bench Press",
          "Vert Leap (in)",
          "Broad Jump (in)",
          Shuttle,
          "Three Cone",
          "Edge Combine Score"
        ) %>%
        dplyr::filter(Name == input$profile_player_selection) 
        
      
    })
#> Error in reactive({: could not find function "reactive"
    
  output$combine_status_color <- renderUI({
    
    if(ed_color()[,"Edge Combine Score"] > 90 ) {
      a <- paste("<span style=color:#2DBF29>",  "ELITE Combine Score")
    } 
    else if(ed_color()[,"Edge Combine Score"] < 90 & ed_color()[,"Edge Combine Score"] > 80 ) {
      a <- paste("<span style=color:#1955CE>",  "GOOD Combine Score")
    } 
    else if(ed_color()[,"Edge Combine Score"] < 80 & ed_color()[,"Edge Combine Score"] > 70 ) {
      a <- paste("<span style=color:#FA8B05>",  "STANDARD Combine Score")
    } 
    else if(ed_color()[,"Edge Combine Score"] < 70 & ed_color()[,"Edge Combine Score"] > 60 ) {
      a <- paste("<span style=color:#FA8B05>", "AVERAGE Combine Score")
    }
    else if(ed_color()[,"Edge Combine Score"] < 60 & ed_color()[,"Edge Combine Score"] > 50 ) {
      a <- paste("<span style=color:#FA8B05>",  "POOR Combine Score")
    }
    else if(ed_color()[,"Edge Combine Score"] < 50 & ed_color()[,"Edge Combine Score"] > 40 ) {
      a <- paste("<span style=color:#FA8B05>", "WORST Combine Score")
    }
    
     HTML(a)
    
  })

You can (hopefully) see that I am trying to filter a large dataframe by the same set of variables but change on the userinput of name. The RenderUI and if statements are meant to read a certain score in the dataframe and deliver the corresponding text. Again, most names work but only a few kick the error.

Aucun commentaire:

Enregistrer un commentaire