mercredi 24 février 2021

replace heatmap input vector if checkbox selected by input selector value in Shiny

I’m still a rookie at shiny and I’m really struggling. I inherited a complex code that I’ve been modifying. I’m stuck on something : A table returns values, I managed to pull the average and make it appear below that table (project_gap_table). I added a checkbox (override) that if clicked offers the possibility to change that average with an input selector (gapover). The issue I have is that I don’t know where to input a condition so that the input selection replaces that average that feeds into a heatmap. I’ve tried for 2 days now. I suspect I can’t call the checkbox that’s in the UI but I don’t know how to do it. My UI and servers are too long so here are parts of them :

column(
                6,
                DTOutput(ns('project_gap_table')) %>% withSpinner(),
                align="right",textOutput(ns("selected_var")),
                fluidRow(column(3,
                  class = "text-left",
                  checkboxInput(inputId = "override",
                                "Override Gap Suggestion",
                                value=FALSE#,
                                #multiple = FALSE,
                                #selected = c(0),
                                #inline = TRUE
                  )
                ),

                conditionalPanel(condition = "input.override == 1",
                    (column(5,offset=1,textInput(
                      ns('rational'),
                      'Rational',
                      width = '100%'
                    ))),column(3,
                               id="gapover",
                               pickerInput(
                                 ns("gapover"),
                                 "Gap Overriding",
                                 choices = choices$gapover,
                                 multiple = FALSE,
                                 width = "100%"
                      )),textOutput(ns("gapover"))
                    )

                    ),

Parts of my server :

  gap_selection <- reactive({input$gapover})
  output$gapover <- renderText({
    gap_selection()
  })

  project_gap_score <- reactive({
     req(input$gapover)
     if_else(input$override == 0,
    (project_gap_table_prep() %>%
      select(rank) %>%
      drop_na() %>%
      mutate(rank = as.numeric(str_extract(rank, '\\d{1}'))) %>%
      summarise(score = round(mean(rank))) %>%
      mutate(
        label = case_when(
          score == 1 ~ 'Low',
          score == 2 ~ 'Medium',
          score == 3 ~ 'Large',
          score == 4 ~ 'Very Large'
        ))
       ),
     gap_selection)
  })

  output$selected_var <- renderText({
    paste("Suggested rating", project_gap_score()$label)
  })

screenshot of my table I get the error Warning: Error in : true must be length 0 (length of condition) or one, not 2.

The only other option I’m considering is creating a condition in the UI to output a different table if that box is checked. Any word of advice will be appreciated!




Aucun commentaire:

Enregistrer un commentaire