-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into bugfix/windows-ci
- Loading branch information
Showing
14 changed files
with
266 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#' Remove Output from Shiny Session | ||
#' | ||
#' The removal of the named output in a shiny session. | ||
#' | ||
#' @param id Output value name | ||
#' @param selector The HTML selector to remove the UI for. By default it is the | ||
#' tag where the ID matches the output, but might need to be adjusted for | ||
#' different inputs. | ||
#' @param session The Shiny session to remove the output from | ||
#' | ||
#' @return | ||
#' An invisible `TRUE` value confirming that the output has been removed. | ||
#' | ||
#' @examplesIf interactive() | ||
#' library(shiny) | ||
#' library(shiny.destroy) | ||
#' | ||
#' ui <- fluidPage( | ||
#' numericInput("number", "Select number:", 5, 1, 10), | ||
#' p("Selected number:", textOutput("number_out", inline = TRUE)), | ||
#' actionButton("delete", "Remove output") | ||
#' ) | ||
#' | ||
#' server <- function(input, output, session) { | ||
#' output$number_out <- renderText(input$number) | ||
#' | ||
#' observeEvent( | ||
#' input$delete, | ||
#' removeOutput("number_out") | ||
#' ) | ||
#' } | ||
#' | ||
#' shinyApp(ui, server) | ||
#' | ||
#' @export | ||
removeOutput <- function(id, selector = paste0("#", id), session = getDefaultReactiveDomain()) { | ||
shiny::removeUI(selector, immediate = TRUE, session = session) | ||
|
||
destroyOutput(id, session = session) | ||
session$requestFlush() | ||
|
||
invisible(TRUE) | ||
} | ||
|
||
#' Remove Output from Shiny Session | ||
#' | ||
#' The removal of the named output in a shiny session. | ||
#' | ||
#' @param id Output value name | ||
#' @param session The Shiny session to remove the output from | ||
#' | ||
#' @noRd | ||
destroyOutput <- function(id, session = getDefaultReactiveDomain()) { | ||
session$defineOutput(id, NULL, NULL) | ||
session$.__enclos_env__$private$.outputs[[id]] <- NULL | ||
session$.__enclos_env__$private$.outputOptions[[id]] <- NULL | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
test_that("Input is fully removed from shiny application", { | ||
ui <- fluidPage( | ||
numericInput("number", "Choose a number", 5, 1, 10), | ||
actionButton("destroy", "Destroy input"), | ||
textOutput("number_input") | ||
) | ||
|
||
server <- function(input, output, session) { | ||
output$number_input <- renderText(input$number) | ||
observeEvent(input$destroy, removeInput("number")) | ||
} | ||
|
||
app <- shinytest2::AppDriver$new(shinyApp(ui, server), name = "basic_app") | ||
on.exit(app$stop()) | ||
|
||
expect_equal(app$get_value(input = "number"), 5L, ignore_attr = TRUE) | ||
expect_identical(app$get_value(output = "number_input"), "5") | ||
|
||
app$click(input = "destroy") | ||
expect_error(app$click(input = "number")) | ||
expect_null(app$get_value(input = "number")) | ||
expect_identical(app$get_value(output = "number_input"), "") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
test_that("Output is fully removed from shiny application", { | ||
ui <- fluidPage( | ||
numericInput("number", "Choose a number", 5, 1, 10), | ||
actionButton("destroy", "Destroy input"), | ||
textOutput("number_input") | ||
) | ||
|
||
server <- function(input, output, session) { | ||
output$number_input <- renderText(input$number) | ||
observeEvent(input$destroy, removeOutput("number_input")) | ||
} | ||
|
||
app <- shinytest2::AppDriver$new(shinyApp(ui, server), name = "basic_app") | ||
on.exit(app$stop()) | ||
|
||
expect_equal(app$get_value(input = "number"), 5L, ignore_attr = TRUE) | ||
expect_identical(app$get_value(output = "number_input"), "5") | ||
|
||
app$click(input = "destroy", wait_ = FALSE) | ||
expect_equal(app$get_value(input = "number"), 5L, ignore_attr = TRUE) | ||
# If ever to fully remove an output, this test will update. For now, | ||
# have to settle with validation error | ||
expect_setequal(app$get_value(output = "number_input")$type, c("shiny.silent.error", "validation")) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.