Hi Andres 
Sure. Here I use {R6} to manage a reactive value at the process level.
You can run the app, and then open a new session (i.e., copy+paste the URL in a different browser tab) and check that they are sync'd.
library(shiny)
library(R6)
# Create a process-level (i.e. in global scope) reactive-value manager.
ValueManager <- R6::R6Class(
classname = "ValueManager",
public = list(
initialize = function() {
private$reactive_inner_counter <- reactiveVal(1)
},
set_value = function(value) {
private$reactive_inner_counter(value)
},
get_value = function() {
private$reactive_inner_counter()
}
),
private = list(
reactive_inner_counter = NULL
)
)
# Instantiate the manager outside the server function..
value_manager <- ValueManager$new()
ui <- fluidPage(
sliderInput("slider_value", label = "# of rows to show",min = 1, max = 50, value = 10),
tableOutput("table")
)
server <- function(input, output, session) {
observeEvent(input$slider_value, {
value_manager$set_value(input$slider_value)
})
output$table <- renderTable({
current_slider_value <- value_manager$get_value()
iris[1:current_slider_value, ]
})
}
shinyApp(ui, server)
Cheers!
This post was published by an Appsilon team member. Our company can help you get the most out of RShiny and Posit/RStudio products.
Check our open positions here.
Appsilon: Building impactful RShiny Dashboards and providing R coding services.
