countBars | R Documentation |
shiny
element displaying a series of progress bars and observation counts.
countBars(inputId, choices, countsmax, countsnow = NULL)
updateCountBars(
session = getDefaultReactiveDomain(),
inputId,
choices,
countsmax,
countsnow = NULL
)
inputId |
( |
choices |
( |
countsmax |
( |
countsnow |
( |
session |
( |
List of shiny.tag
s.
Creates a number of progress bar elements, one for each value of choices
.
The widths of all progress bars add up to the full width of the container.
Each progress bar has a text label that contains the name of the value and the number of counts.
If the filter panel is used with count_type = "all"
, the progress bars will be filled
according to the number of counts remaining in the current selection and the label will show
both the current and the total number of counts.
Each child element can have a unique id
attribute to be used independently.
# use non-exported function from teal.slice
include_js_files <- getFromNamespace("include_js_files", "teal.slice")
include_css_files <- getFromNamespace("include_css_files", "teal.slice")
countBars <- getFromNamespace("countBars", "teal.slice")
updateCountBars <- getFromNamespace("updateCountBars", "teal.slice")
library(shiny)
choices <- sample(as.factor(c("a", "b", "c")), size = 20, replace = TRUE)
counts <- table(choices)
labels <- countBars(
inputId = "counts",
choices = c("a", "b", "c"),
countsmax = counts,
countsnow = unname(counts)
)
ui <- fluidPage(
tags$div(
class = "choices_state",
include_js_files("count-bar-labels.js"),
include_css_files(pattern = "filter-panel"),
checkboxGroupInput(
inputId = "choices",
selected = levels(choices),
choiceNames = labels,
choiceValues = levels(choices),
label = NULL
)
)
)
server <- function(input, output, session) {
observeEvent(input$choices, {
new_counts <- counts
new_counts[!names(new_counts) %in% input$choices] <- 0
updateCountBars(
inputId = "counts",
choices = levels(choices),
countsmax = counts,
countsnow = unname(new_counts)
)
})
}
if (interactive()) {
shinyApp(ui, server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.