Skip to contents

whence_opened() lets the app react when the viewer opens the panel of an output: for example, to filter other outputs to the row of a table that the viewer is looking at. Call it in a server function or a module server. It gives a reactive expression.

Usage

whence_opened(outputId, session = shiny::getDefaultReactiveDomain())

Arguments

outputId

The id of a whence output, as in the UI. In a module, give the id without the namespace, as for output$id.

session

The session. The default is the current one.

Value

A reactive expression.

Details

The reactive gives NULL while no panel of that output is open. While one is open, it gives a list:

Only one panel is open at a time.

Examples

if (interactive() && requireNamespace("dplyr", quietly = TRUE)) {
  library(shiny)
  library(dplyr, warn.conflicts = FALSE)

  ui <- fluidPage(
    whenceTableOutput("by_cyl", label = "Cars by cylinders"),
    textOutput("looking_at")
  )
  server <- function(input, output, session) {
    output$by_cyl <- renderWhenceTable(
      mtcars |> group_by(cyl) |> summarise(cars = n())
    )
    opened <- whence_opened("by_cyl")
    output$looking_at <- renderText({
      req(opened())
      paste("The viewer is looking at", opened()$data$cyl, "cylinders.")
    })
  }
  shinyApp(ui, server)
}