Update plots in different tabPanels with one action button Shiny

In a bigger app I am building I have a situation where I need to update multiple plots in different tabPanel using one action button.

Now, the updating of the plots after pressing the action button works. However, if I go back to a previous tabPanel, I would like to work with the cached value in dataNorm or dataUnif to still be able to update the title of the plot.


  1. Click go to view Uniform hist
  2. Update Unif hist title
  3. go to plotNorm tabPanel
  4. Click go to view Normal hist
  5. Update Norm hist title
  6. go back to plotUnif tabPanel (dont click go!)
  7. Try to update title...

Below you see the example:


ui <- fluidPage(
            tabsetPanel(id = "tabset",
                                 numericInput("unifCount", "Count", 100),
                                 sliderInput("unifRange", "Range", min = -100, max = 100, value = c(-10, 10)),
                                 textInput(inputId = 'titleUnif', "Change Title"),
                                 numericInput("normCount", "Count", 100),
                                 numericInput("normMean", "Mean", 0),
                                 numericInput("normSd", "Std Dev", 1),
                                 textInput(inputId = 'titleNorm', "Change Title"),
            actionButton("go", "Plot")

server <- function(input, output){
    # Record how many times go has been pushed
    v <- reactiveValues(go_rec = 0L)
    # Compute new dataUnif only if input$go in new and on that tab (wanted effect: otherwise return cached value)
    dataUnif <- eventReactive(input$go,{
        shiny::req(input$go > v$go_rec, input$tabset == "plotUnif", cancelOutput = T)
        v$go_rec <- input$go
        return(runif(input$unifCount, input$unifRange[1], input$unifRange[2]))
    # same as dataUnif
    dataNorm <- eventReactive(input$go,{
        shiny::req(input$go > v$go_rec, input$tabset == "plotNorm", cancelOutput = T)
        v$go_rec <- input$go
        return(rnorm(input$normCount, input$normMean, input$normSd))
    # Disply hist (be able to change title)
    output$plotUnif <- renderPlot({
        hist(dataUnif(), main = input$titleUnif)
    output$plotNorm <- renderPlot({
        hist(dataNorm(), main = input$titleNorm)

shinyApp(ui, server)

comment out these reqs and the code gives the desired behaviour, perhaps rethink them.