1

I am writing a Shiny app where the prettyCheckboxGroup choices are populated by a user-uploaded .csv file. If I manually set the choices (e.g. "A", "B", "C"), then I can change status, shape, outline, etc. However, if I use updatePrettyCheckboxGroup based on an observeEvent in my server code, then the result is just the default style.

ui <- navbarPage("Tabbed page",
                 tabPanel("Works",
                          prettyCheckboxGroup(
                            inputId = "Id001",
                            label = "Checkboxes with status",
                            choices = c("A", "B", "C"),
                            inline = TRUE,
                            status = "danger",
                            shape = "round"),

                 ),
                 tabPanel("Doesn't Work",
                          fileInput("Line_Dataset", label = "Choose Data"),                    
                          prettyCheckboxGroup(
                            inputId = "Broken",
                            label = "Checkboxes with status", 
                            choices = NULL,
                            inline = TRUE,
                            status = "danger",
                            shape = "round"),
                 )
)

server <- function(input, output, session) {
  LineFile <- eventReactive(c(input$Line_Dataset), {
    read_csv(input$Line_Dataset$datapath, col_names = T)
  })
  
  observeEvent(input$Line_Dataset,
               {elements_line_data <- LineFile() %>%
                 colnames()
               
               updatePrettyCheckboxGroup(session,
                                         "Broken",
                                         choices = elements_line_data)
               })
  
}
shinyApp(ui,server)

Where should I put the status and shape arguments when using updatePrettyCheckboxGroup? Do they need to go in the server file?

Note, I get the same results when trying to use awesomeCheckboxGroup and update... but I chose to use pretty because of the number of formatting options.

Thanks, Jeremy

P.S. I apologise for not providing a .csv but any file will work

EDIT: Screenshots of the issue. I would like the Checkbox buttons in the "Doesn't work" tab to look the same as those in "Works". enter image description here

JJGabe
  • 383
  • 1
  • 2
  • 10

1 Answers1

1

The function updatePrettyCheckbox() lacks the possibility to pass the arguments status and shape, so the only option to generate the correct checkbox is directly using renderUI(). Anyways, the problem was that because those two arguments weren't present when updatePrettyCheckbox() was called, a default format was re-rendered.

library(shiny)
library(shinyWidgets)
library(tidyverse)

ui <- navbarPage("Tabbed page",
                 tabPanel("Works",
                          prettyCheckboxGroup(
                              inputId = "Id001",
                              label = "Checkboxes with status",
                              choices = c("A", "B", "C"),
                              inline = TRUE,
                              status = "danger",
                              shape = "round")
                          
                 ),
                 tabPanel("Doesn't Work",
                          fileInput("Line_Dataset", label = "Choose Data"),
                 uiOutput('download_with_prettychbx')
                 )
)

server <- function(input, output, session) {
    LineFile <- eventReactive(c(input$Line_Dataset), {
        read_csv(input$Line_Dataset$datapath, col_names = T,)
        
    })
    
    
    
    observeEvent(input$Line_Dataset, {
    
        elements_line_data <- LineFile() %>%
            colnames()

    output$download_with_prettychbx <- renderUI({
    tagList(
                        
    prettyCheckboxGroup(
        inputId = "Broken",
        label = "Checkboxes with status", 
        choices = LineFile(),
        inline = TRUE,
        status = "danger",
        shape = "round")
    )
              
                 })})
    
}
shinyApp(ui,server)
jpdugo17
  • 6,816
  • 2
  • 11
  • 23
  • Thanks for the reply, but unfortunately this isn't working for me. I copied your code into R but when I loaded a .csv it was either in the default format again or I received an error: "All sub-lists in "choices" must be named [No stack trace available]". I have added screenshots to my question to demonstrate. – JJGabe Jun 04 '21 at 23:46
  • I fixed the answer . Turns out that using reactive inside observeEvent was redundant. The issue was with `updatePrettyCheckbox()`. – jpdugo17 Jun 05 '21 at 01:06
  • Thank you, that solved it. And thank you for the explanation because I'm still learning shiny and everything I have learned so far tells me `prettyCheckboxGroup` only goes in the ui code. Out of curiosity, why did you put it all inside a `tagList`? I was able to run it without, I think because of the { }, so I was wondering if creating an HTML tag had some added benefit or functionality. – JJGabe Jun 05 '21 at 13:19