rstudio / rstudio/flexdashboard

how do i know which tab is exposed in an observeEvent()?

Open
#237 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
848
Forks
298
PR merge metrics
No merged PRs in 30d

Description

I need to know, within observeEvent( ... ) whether a particular tab is exposed in the interface. How do I do this? This is similar to the workaround suggested in https://github.com/rstudio/leaflet/issues/590 but with shiny, namely, by adding an "id" to the tabSetPanel(). Can I do this with flexdashboard so I can reference its state within observeEvent()???

ui <- fluidPage(
  tabsetPanel(
    id = "tab_being_displayed", # will set input$tab_being_displayed
    tabPanel("Tab 1"),
    tabPanel("Map Tab",
             leafletOutput("map"),
             selectInput("colors", "Color Scheme",
                         rownames(subset(brewer.pal.info, category %in% c("seq", "div")))
             )
    ),
    selected = "Tab 1"
  )
)

server <- function(input, output, session) {

  # Leaflet Output
  output$map <- renderLeaflet({
    leaflet(quakes) %>% addTiles() %>%
      fitBounds(~min(long), ~min(lat), ~max(long), ~max(lat))
  })
  
 
  # leaflet Proxy
  observe({
    req(input$tab_being_displayed == "Map Tab") # Only display if tab is 'Map Tab'
    # code here.
  })
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied R tabsetPanel and observeEvent example, then review the linked Leaflet issue for the proposed tab-state workaround. Reproduce the flexdashboard case and determine whether the active tab is exposed to observeEvent; done means documenting the supported approach or confirming the limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.