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".
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)