how can i access the value of a shiny reactive output inside the browser console with jquery

9 hours ago 1
ARTICLE AD BOX

I have an app that uses a conditionalPanel that relies on a reactive value. Here's a basic example:

library(shiny) ui <- fluidPage( fluidRow( actionButton("button1", label = "Type 1"), actionButton("button2", label = "Type 2") ), conditionalPanel( condition = "output.selectedType == 'type1'", h4("Type 1 Selected") ), conditionalPanel( condition = "output.selectedType == 'type2'", h4("Type 2 Selected") ) ) server <- function(input, output, session) { val_selectedType <- reactiveVal(value = NULL) output$selectedType <- reactive({ val_selectedType() }) outputOptions(output, "selectedType", suspendWhenHidden = FALSE) observeEvent(input$button1, { val_selectedType('type1') }) observeEvent(input$button2, { val_selectedType('type2') }) } shinyApp(ui = ui, server = server)

In the browser's dev console, how can I use jquery to get the value of "output.selectedType"? In other words, how is the browser client able to access that value and determine that output.selectedType is 'type1' or 'type2'?

For example, I can use document.querySelector('#button1').textContent to grab the text in the button, but how would i similarly grab the value from 'output.selectedType'?

I'm trying to understand so that I can debug a more complicated app. Thank you.

Read Entire Article