title: Shiny: How to initialize empty reactiveValues with an actionButton?
body: <p><strong>Background:</strong> In my app, I have built a pop-up modal wherein users can define variables/parameters and they're subsequently stored in a <code>reactiveValues()</code> once an <code>actionButton</code> is pressed. This appears to work fine.</p>
  <p><a href="https://i.stack.imgur.com/QxXpV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QxXpV.png" alt="enter image description here" /></a></p>
  <p><strong>The problem:</strong> I have a separate <code>actionButton</code> which is supposed to clear/empty the <code>reactiveValues</code> that holds the inputs above. Unfortunately, this doesn't seem to work--that is, pressing the button doesn't do anything.</p>
  <p><strong>Minimally-reproducible code:</strong></p>
  <pre><code>library(DT)
  
  # UI modules
  sidebarCharts &lt;- function(id) {
    ns &lt;- NS(id)
    tagList(
      p(),
      actionButton(ns(&quot;settings&quot;), &quot;Settings&quot;, 
                  icon = icon(&quot;cogs&quot;), 
                  width = '100%',
                  class = &quot;btn btn-info&quot;),
      p(),
      actionButton(ns(&quot;refreshMainChart&quot;) ,&quot;Refresh&quot;, 
                   icon(&quot;refresh&quot;),
                   width = '100%',
                   class = &quot;btn btn-primary&quot;),
      p(),
      textOutput(ns(&quot;info&quot;))  # FOR DEBUGGING
    )
  }
  
  mainChartUI &lt;- function(id) {
    ns &lt;- NS(id)
    plotOutput(ns(&quot;mainChart&quot;), width = &quot;100%&quot;)
  }
  
  # UI module for the 2 buttons in the modal:
  modalFooterUI &lt;- function(ns) {
    tagList(
      modalButton(&quot;Cancel&quot;, icon(&quot;remove&quot;)),
      actionButton(ns(&quot;modalApply&quot;), &quot;Apply&quot;,
                   icon = icon(&quot;check&quot;))
    )
  }
  
  # module server
  modal &lt;- function(input, output, session) {
    
    # Init reactiveValues() to store default values and updated values; https://github.com/rstudio/shiny/issues/1588
    rv &lt;- reactiveValues(clicks = 0, 
                         applyClicks = 0,
                         bins = 20,
                         bandwidth = 1)
    
    reactiveBlotter &lt;- reactiveValues()  # Empty reactiveValues()
    
    # DEBUGGING
    output$info &lt;- renderText({
      paste(&quot;You clicked the 'Settings' button&quot;,
            rv$clicks,
            &quot;times. You clicked the 'Apply' button&quot;,
            rv$applyClicks,
            &quot;times. The bin size is currently set to&quot;,
            rv$bins,
            &quot;and the bandwidth is currently set to&quot;,
            rv$bandwidth)
    })
    
    settngsModal &lt;- function(ns) {
      modalDialog(
        
        withTags({  # UI elements for the modal go in here
          fluidPage(
            # titlePanel(&quot;Modal title optional&quot;),
            sidebarLayout(
              sidebarPanel(
                  selectInput(ns(&quot;n_breaks&quot;),
                              label = &quot;Number of bins:&quot;,
                              choices = c(10, 20, 35, 50),
                              selected = rv$bins, width = '100%'),
                  sliderInput(ns(&quot;bw_adjust&quot;),
                              label = &quot;Bandwidth adjustment:&quot;,
                              min = 0.2,
                              max = 2,
                              value = rv$bandwidth,
                              step = 0.2, width = '100%'),
                  textInput(ns(&quot;testInputName&quot;),
                            label = &quot;Name&quot;,
                            width = '100%'),
                  selectInput(ns(&quot;testInput&quot;),
                              label = &quot;Test Input&quot;,
                              choices = c('A','B','C'),
                              width = '100%'),
                  selectInput(ns(&quot;testInput2&quot;),
                              label = &quot;Test Input 2&quot;,
                              choices = c('D','E','F'),
                              width = '100%'),
                  actionButton(ns(&quot;addToRV&quot;),
                               label = 'Add to reactiveValues'),
                  p(),
                  actionButton(ns(&quot;clearRV&quot;),
                               label = 'Clear reactiveValues')
              ),
              mainPanel(
                # &quot;Blotter table goes here.&quot;,
                fluidRow(
                  DT::DTOutput(ns(&quot;blotterDT&quot;))
                )
              )
            )
          )
        }),
        title = &quot;Settings&quot;,
        footer = modalFooterUI(ns), 
        size = &quot;l&quot;,
        easyClose = FALSE,
        fade = TRUE)
    }
    
    # Sidebar 'Settings' modal
    observeEvent(input$settings, {
      showModal(settngsModal(session$ns))  # This opens the modal; settngsModal() defined below
      rv$clicks &lt;- rv$clicks + 1  # FOR DEBUGGING
    })
    
    observeEvent(input$modalApply, {
      rv$applyClicks &lt;- rv$applyClicks + 1  # FOR DEBUGGING
      rv$bins &lt;- input$n_breaks  # This is where I set the reactiveValues() to those inputted into the modal.
      rv$bandwidth &lt;- input$bw_adjust
      removeModal()  # This should dismiss the modal (but it doesn't seem to work)
    })
    
    observeEvent(input$addToRV, { 
      req(input$testInputName, input$testInput, input$testInput2)
      reactiveBlotter[[input$testInputName]] &lt;- list(testInputName = input$testInputName, 
                                                     testInput = input$testInput,
                                                     testInput2 = input$testInput2)
    })
    
    observeEvent(input$clearRV, {
      reactiveBlotter &lt;- reactiveValues()  # This is the part that doesn't seem to work
    })
    
    blotterDf &lt;- reactive({
      do.call(&quot;rbind&quot;, lapply(reactiveBlotter, FUN = function(x) {
        data.frame(name = x[[&quot;testInputName&quot;]],
                   input1 = x[[&quot;testInput&quot;]],
                   input2 = x[[&quot;testInput2&quot;]])
      }))
    })
    
    output$blotterDT &lt;- DT::renderDT({
      validate(need(length(names(reactiveBlotter)) &gt; 0, 
                     &quot;Add something to the blotter.&quot;))
      DT::datatable(blotterDf(),
                    style = 'bootstrap',
                    class = 'table-bordered table-condensed',
                    rownames = TRUE,
                    options = list(dom = 't',
                                   paging = F)
      )
    })
    
    output$mainChart &lt;- renderPlot({
      input$refreshMainChart  # Take dependency on the 'Refresh' buton
      
      hist(faithful$eruptions, probability = TRUE, 
           breaks = as.numeric(rv$bins),  
           xlab = &quot;Duration (minutes)&quot;,
           main = &quot;Geyser Eruption Duration&quot;)
      
      dens &lt;- density(faithful$eruptions, adjust = rv$bandwidth)
      lines(dens, col = &quot;blue&quot;)
    })
    
  }
  
  # Define UI
  ui &lt;- fluidPage(
    
    # Application title
    titlePanel(&quot;stackoverflow example&quot;),
    
    sidebarLayout(
      sidebarPanel(
        sidebarCharts(&quot;main&quot;)
      ),
      mainPanel(
        mainChartUI(&quot;main&quot;)
      )
    )
  )
  
  # Server logic
  server &lt;- function(input, output) {
    callModule(modal, &quot;main&quot;)
  }
  
  # Complete app with UI and server components
  shinyApp(ui, server)
  </code></pre>
  <p>What am I missing here? Any help is much appreciated!</p>