Skip to content

Commit

Permalink
Add removeOutput function
Browse files Browse the repository at this point in the history
  • Loading branch information
ashbaldry committed Aug 6, 2024
1 parent 8cb1598 commit 03b0bc6
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export(destroyModule)
export(makeModuleServerDestroyable)
export(makeModuleUIDestroyable)
export(removeInput)
export(removeOutput)
export(runDestroyExample)
import(shiny)
44 changes: 44 additions & 0 deletions R/removeOutput.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
#' 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)

Check warning on line 37 in R/removeOutput.R

View check run for this annotation

Codecov / codecov/patch

R/removeOutput.R#L37

Added line #L37 was not covered by tests

destroyOutput(id, session = session)
session$requestFlush()

Check warning on line 40 in R/removeOutput.R

View check run for this annotation

Codecov / codecov/patch

R/removeOutput.R#L39-L40

Added lines #L39 - L40 were not covered by tests

invisible(TRUE)

Check warning on line 42 in R/removeOutput.R

View check run for this annotation

Codecov / codecov/patch

R/removeOutput.R#L42

Added line #L42 was not covered by tests
}

#' Remove Output from Shiny Session
#'
#' The removal of the named output in a shiny session.
Expand Down
50 changes: 50 additions & 0 deletions man/removeOutput.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vignettes/introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ shiny::runExample(

### UI


The UI for a module is removed in the same way the UI is removed for an input.

### Observers

Expand Down

0 comments on commit 03b0bc6

Please sign in to comment.