Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing the example apps #219

Merged
merged 11 commits into from
Jan 30, 2024
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
28 changes: 14 additions & 14 deletions R/draggable_buckets.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
#' @details `shinyvalidate` validation can be used with this widget. See example below.
#'
#' @examples
#'
#' ui <- shiny::fluidPage(
#' library(shiny)
#' ui <- fluidPage(
#' draggable_buckets("id", "Choices #1", c("a", "b"), c("bucket1", "bucket2")),
#' draggable_buckets("id2", "Choices #2", letters, c("vowels", "consonants")),
#' shiny::verbatimTextOutput("out"),
#' shiny::verbatimTextOutput("out2")
#' verbatimTextOutput("out"),
#' verbatimTextOutput("out2")
#' )
#' server <- function(input, output) {
#' iv <- shinyvalidate::InputValidator$new()
Expand All @@ -29,30 +29,30 @@
#' )
#' iv$enable()
#'
#' shiny::observeEvent(list(input$id, input$id2), {
#' observeEvent(list(input$id, input$id2), {
#' print(isolate(input$id))
#' print(isolate(input$id2))
#' })
#' output$out <- shiny::renderPrint({
#' output$out <- renderPrint({
#' iv$is_valid()
#' input$id
#' })
#' output$out2 <- shiny::renderPrint(input$id2)
#' output$out2 <- renderPrint(input$id2)
#' }
#' if (interactive()) shiny::shinyApp(ui, server)
#' if (interactive()) shinyApp(ui, server)
#'
#' # With default elements in the bucket
#' ui <- shiny::fluidPage(
#' ui <- fluidPage(
#' draggable_buckets("id", "Choices #1", c("a", "b"), list(bucket1 = character(), bucket2 = c("c"))),
#' shiny::verbatimTextOutput("out")
#' verbatimTextOutput("out")
#' )
#' server <- function(input, output) {
#' shiny::observeEvent(input$id, {
#' print(shiny::isolate(input$id))
#' observeEvent(input$id, {
#' print(isolate(input$id))
#' })
#' output$out <- shiny::renderPrint(input$id)
#' output$out <- renderPrint(input$id)
#' }
#' if (interactive()) shiny::shinyApp(ui, server)
#' if (interactive()) shinyApp(ui, server)
draggable_buckets <- function(input_id, label, elements = character(), buckets) {
checkmate::assert_string(input_id)
checkmate::assert_true(inherits(label, "character") || inherits(label, "shiny.tag"))
Expand Down
6 changes: 4 additions & 2 deletions R/get_dt_rows.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@
#'
#' @examples
#' library(shiny)
#' library(DT)
#'
#' ui <- function(id) {
#' ns <- NS(id)
#' tagList(
#' DT::DTOutput(ns("data_table")),
#' DTOutput(ns("data_table")),
#' get_dt_rows(ns("data_table"), ns("dt_rows"))
#' )
#' }
#'
#' # use the input$dt_rows in the Shiny Server function
#' server <- function(id) {
#' moduleServer(id, function(input, output, session) {
#' output$data_table <- DT::renderDataTable(
#' output$data_table <- renderDataTable(
#' {
#' iris
#' },
Expand Down
14 changes: 8 additions & 6 deletions R/nested_closeable_modal.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#' @examples
#' # nolint start
#' library(shiny)
#' library(shinyjs)
#'
#' ui <- fluidPage(
#' shinyjs::useShinyjs(),
#' useShinyjs(),
#' actionButton("show_1", "$('#modal_1').modal('show')"),
#' nested_closeable_modal(
#' "modal_1",
Expand Down Expand Up @@ -61,20 +63,20 @@
#' )
#' server <- function(input, output) {
#' observeEvent(input$show_1, {
#' shinyjs::runjs("$('#modal_1').modal('show')")
#' runjs("$('#modal_1').modal('show')")
#' })
#' observeEvent(input$show_2, {
#' shinyjs::runjs("$('#modal_2').modal('show')")
#' runjs("$('#modal_2').modal('show')")
#' })
#' observeEvent(c(input$hide_1, input$hide_all), {
#' shinyjs::runjs("$('#modal_1').modal('hide')")
#' runjs("$('#modal_1').modal('hide')")
#' })
#' observeEvent(input$hide_2, {
#' shinyjs::runjs("$('#modal_2').modal('hide')")
#' runjs("$('#modal_2').modal('hide')")
#' })
#' }
#' if (interactive()) {
#' shiny::shinyApp(ui, server)
#' shinyApp(ui, server)
#' }
#' # nolint end
nested_closeable_modal <- function(id, ..., modal_args = list(easyClose = TRUE)) {
Expand Down
158 changes: 72 additions & 86 deletions R/optionalInput.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,101 +52,87 @@
#' )
#' }
#'
#'
#' app <- shinyApp(
#' ui = ui_grid(
#' div(
#' optionalSelectInput(
#' inputId = "c1",
#' label = "Fixed choices",
#' choices = LETTERS[1:5],
#' selected = c("A", "B"),
#' fixed = TRUE
#' ),
#' verbatimTextOutput(outputId = "c1_out")
#' ui <- ui_grid(
#' div(
#' optionalSelectInput(
#' inputId = "c1",
#' label = "Fixed choices",
#' choices = LETTERS[1:5],
#' selected = c("A", "B"),
#' fixed = TRUE
#' ),
#' div(
#' optionalSelectInput(
#' inputId = "c2",
#' label = "Single choice",
#' choices = "A",
#' selected = "A"
#' ),
#' verbatimTextOutput(outputId = "c2_out")
#' verbatimTextOutput(outputId = "c1_out")
#' ),
#' div(
#' optionalSelectInput(
#' inputId = "c2",
#' label = "Single choice",
#' choices = "A",
#' selected = "A"
#' ),
#' div(
#' optionalSelectInput(
#' inputId = "c3",
#' label = "NULL choices",
#' choices = NULL
#' ),
#' verbatimTextOutput(outputId = "c3_out")
#' verbatimTextOutput(outputId = "c2_out")
#' ),
#' div(
#' optionalSelectInput(
#' inputId = "c3",
#' label = "NULL choices",
#' choices = NULL
#' ),
#' div(
#' optionalSelectInput(
#' inputId = "c4",
#' label = "Default",
#' choices = LETTERS[1:5],
#' selected = "A"
#' ),
#' verbatimTextOutput(outputId = "c4_out")
#' verbatimTextOutput(outputId = "c3_out")
#' ),
#' div(
#' optionalSelectInput(
#' inputId = "c4",
#' label = "Default",
#' choices = LETTERS[1:5],
#' selected = "A"
#' ),
#' div(
#' optionalSelectInput(
#' inputId = "c5",
#' label = "Named vector",
#' choices = c(`A - value A` = "A", `B - value B` = "B", `C - value C` = "C"),
#' selected = "A"
#' ),
#' verbatimTextOutput(outputId = "c5_out")
#' verbatimTextOutput(outputId = "c4_out")
#' ),
#' div(
#' optionalSelectInput(
#' inputId = "c5",
#' label = "Named vector",
#' choices = c(`A - value A` = "A", `B - value B` = "B", `C - value C` = "C"),
#' selected = "A"
#' ),
#' div(
#' selectInput(
#' inputId = "c6_choices", label = "Update choices", choices = letters, multiple = TRUE
#' ),
#' optionalSelectInput(
#' inputId = "c6",
#' label = "Updated choices",
#' choices = NULL,
#' multiple = TRUE,
#' fixed_on_single = TRUE
#' ),
#' verbatimTextOutput(outputId = "c6_out")
#' )
#' verbatimTextOutput(outputId = "c5_out")
#' ),
#' server = function(input, output, session) {
#' observeEvent(input$c6_choices, ignoreNULL = FALSE, {
#' updateOptionalSelectInput(
#' session = session,
#' inputId = "c6",
#' choices = input$c6_choices,
#' selected = input$c6_choices
#' )
#' })
#'
#' output$c1_out <- renderPrint({
#' input$c1
#' })
#' output$c2_out <- renderPrint({
#' input$c2
#' })
#' output$c3_out <- renderPrint({
#' input$c3
#' })
#' output$c4_out <- renderPrint({
#' input$c4
#' })
#' output$c5_out <- renderPrint({
#' input$c5
#' })
#' output$c6_out <- renderPrint({
#' input$c6
#' })
#' }
#' div(
#' selectInput(
#' inputId = "c6_choices", label = "Update choices", choices = letters, multiple = TRUE
#' ),
#' optionalSelectInput(
#' inputId = "c6",
#' label = "Updated choices",
#' choices = NULL,
#' multiple = TRUE,
#' fixed_on_single = TRUE
#' ),
#' verbatimTextOutput(outputId = "c6_out")
#' )
#' )
#'
#' server <- function(input, output, session) {
#' observeEvent(input$c6_choices, ignoreNULL = FALSE, {
#' updateOptionalSelectInput(
#' session = session,
#' inputId = "c6",
#' choices = input$c6_choices,
#' selected = input$c6_choices
#' )
#' })
#'
#' output$c1_out <- renderPrint(input$c1)
#' output$c2_out <- renderPrint(input$c2)
#' output$c3_out <- renderPrint(input$c3)
#' output$c4_out <- renderPrint(input$c4)
#' output$c5_out <- renderPrint(input$c5)
#' output$c6_out <- renderPrint(input$c6)
#' }
#'
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' shinyApp(ui, server)
#' }
#'
optionalSelectInput <- function(inputId, # nolint
Expand Down
Loading
Loading