title: *** caught segfault ***; address 0x5573328516d8, cause 'memory not mapped' in R shiny (golem) app deployed via shinyapps.io
body: <p>I have got a problem with my R Shiny app which runs perfectly fine locally but irregularly returns &quot;Disconnected from the server: Reload&quot; when deployed via shinyapps.io. <strong>Note</strong> that users do not get disconnected every time they click the &quot;Create/update graph!&quot;-Button, but instead (strangely enough) only irregularly.</p>
  <p>For reference, here are the logged messages that I focused on:</p>
  <pre><code>2021-07-13T12:24:26.495243+00:00 shinyapps[4159264]:  *** caught segfault ***
  2021-07-13T12:24:26.495244+00:00 shinyapps[4159264]: address 0x5573328516d8, cause 'memory not mapped'
  </code></pre>
  <p>Followed by a traceback starting with:
  <strong><code>2021-07-13T12:24:26.497790+00:00 shinyapps[4159264]: 1: policy %in% input$recycling_option_choice_checkbox</code></strong>
  and ending in:</p>
  <pre><code>2021-07-13T12:24:56.324135+00:00 shinyapps[4159264]: 91: local({    if (identical(.Platform$OS.type, &quot;unix&quot;)) {        whoami &lt;- system(&quot;whoami&quot;, intern = TRUE)        if (identical(whoami, &quot;root&quot;)) {            stop(&quot;Attempted to run application as whoami=&quot;, whoami,                &quot;; USER=&quot;, Sys.getenv(&quot;USER&quot;))        }    } ...
  2021-07-13T12:24:56.324136+00:00 shinyapps[4159264]: An irrecoverable exception occurred. R is aborting now ...
  </code></pre>
  <p>Since the app is built in a golem framework, I am not able to provide a minimal/reproducible example. The following lines of code are intended to give you an idea of how the module is structured. Note also that users only get disconnected from time to time when clicking the &quot;Create/update graph!&quot;-Button in a module where subsetting the data used for subsequent plots is subsetted using checkboxGroupInput(). For other moduls with selectInput() instead of checkboxGroupInput(), the app does not only work locally but also on the shinyapps.io-server.</p>
  <h3 id="module-r47c">Module</h3>
  <h4 id="ui-n1eg">UI</h4>
  <pre><code>mod_plotting_ui &lt;- function(id){
    ns &lt;- NS(id)
  
  # Infobox showing by a text and a color whether graph has to be created for the first time (blue), is up to date (green) or has to be updated (red)
  shinydashboard::infoBoxOutput(ns(&quot;informationbox1&quot;), width = 12)
  
  # Action button for the graph
  actionButton(ns(&quot;go&quot;), &quot;Create/update graph!&quot;, icon = icon(&quot;arrow-down&quot;))
  
  # checkboxGroupInput (with bsButton for additional info on specific options)
  sidebarPanel(
              tags$style(HTML('#bsButton_recycling_option_choice_checkbox {margin-top: 30px}')),
              fluidRow(
                column(10,
                       tags$div(
                         checkboxGroupInput(ns(&quot;recycling_option_choice_checkbox&quot;), &quot;Choose recycling options:&quot;,
                                            c(&quot;Option 1&quot; = &quot;Option 1&quot;,
                                              &quot;Option 2&quot; = &quot;Option 2&quot;
                                              &quot;Option 3&quot; = &quot;Option 3&quot;,
                                              &quot;Option 4&quot; = &quot;Option 4&quot;,
                                              &quot;Option 5&quot; = &quot;Option 5&quot;),
                                            selected = c(&quot;Option 1&quot;))
                       )
                ),
                column(2, 
                       shinyBS::bsButton(ns(&quot;bsButton_recycling_option_choice_checkbox&quot;))
                )
              )
            )
  
  # Description belonging to the previous bsButton
  shinyBS::bsPopover(id = ns(&quot;bsButton_recycling_option_choice_checkbox&quot;), title = HTML(paste(&quot;&lt;strong&gt;Description&lt;/strong&gt;&quot;)),
                           content = HTML(&quot;...&quot;),
                           placement = &quot;right&quot;, 
                           trigger = &quot;focus&quot;,  options = list(container = &quot;body&quot;))
  
  }
  </code></pre>
  <h4 id="server-cqeq">Server</h4>
  <pre><code>mod_plotting_server &lt;- function(input, output, session, type, parent){
    ns &lt;- session$ns
  
  # Initiate the status
  status &lt;- shiny::reactiveVal()
  
  # Initially (empty/grey) graph
  r &lt;- shiny::reactiveVal(    
      plot = ggplot(dataframe)
    )
    
  # Status after clicking the actionButton (i.e. after creating a graph for the first time or after updating a graph)
  out &lt;- eventReactive( input$go , {
      status(&quot;Well done. Graph is up to date!&quot;)
      paste(&quot;&quot;)
    })
  
  # Subsetting and plotting
  observeEvent( input$go , {
          # Subsetting
          dataframe_subset&lt;- dataframe %&gt;% 
            dplyr::filter(    
              policy %in% input$recycling_option_choice_checkbox               # this seems to be the source of the problem
            )
          # Plotting
          r$plot &lt;- ggplot(data = dataframe_subset, ...) 
  })
  
  # Status at beginning and status when graph needs to be updated
  observeEvent({list(input$recycling_option_choice_checkbox)},
                 ifelse(getCount(input$go) == 0,       #1) getCount(): function returning number of clicks on actionButton (see below) 
                        {status(&quot;Create first graph by clicking the 'Create/update graph!'-Button!&quot;)},
                        {status(&quot;Please update the graph according to your changed inputs by clicking the 'Create/update graph!'-Button!&quot;)})
                 )
                 
  # Maximum and minimum options that can be chosen in checkbox
  observe({
      # Max 3
      if(length(input$recycling_option_choice_checkbox) &gt; 3) {
        showNotification(&quot;You cannot choose more than 3 recycling options at a time.&quot;,
                         duration = 8, type = &quot;message&quot;, closeButton = FALSE)
      }
      # Min 1
      if(getCount(input$go) &gt;= 1 &amp; length(input$recycling_option_choice_checkbox) &lt; 1) {
        showNotification(&quot;You need to choose at least one recycling option.&quot;,
                         duration = 8, type = &quot;message&quot;, closeButton = FALSE)
      }
    })
    
  # Reaction if maximum or minimum is reached
  observe({
      if(length(input$recycling_option_choice_checkbox) &gt; 3){
        updateCheckboxGroupInput(session, &quot;recycling_option_choice_checkbox&quot;, selected = tail(input$recycling_option_choice_checkbox, 3))
      }
      if(length(input$recycling_option_choice_checkbox) &lt; 1){
        updateCheckboxGroupInput(session, &quot;recycling_option_choice_checkbox&quot;, selected = &quot;Option 1&quot;)
      }
    })
  
  # Actual information box showing by a text and a color whether graph has to be created for the first time (blue), is up to date (green) or has to be updated (red)
  output$informationbox1 &lt;- shinydashboard::renderInfoBox({
      shinydashboard::infoBox(
        title = &quot;&quot;,
        value = tags$div(style = &quot;line-height: 1.4;&quot;,
                         tags$h5(renderText({out()}),
                                 renderText({status()}))),
        icon = icon(&quot;exclamation-circle&quot;),
        color = getColor(status(), input$go),      #2) getColor(): function returning a specific color (see below)
        fill = TRUE
      )
    })
  
  # Show graph
  output$plot &lt;- renderPlot({
      r$plot
    })
    
  }
  </code></pre>
  <h2 id="functions-defined-outside-of-the-module-12br">Functions defined outside of the module</h2>
  <pre><code># 1)
  getColor &lt;-  function(placeholder, counts) {
    place &lt;- placeholder
    count &lt;- 0 + counts
    if(count == 0)
    {return('light-blue')}
    else if(count != 0 &amp; place  == &quot;Well done. Graph is up to date!&quot;)
    {return('olive')}
    else return('red')
  }
  # 2)
  getCount &lt;-  function(counts) {
    count &lt;- 0 + counts
    if(count == 0)
    {return(0)}
    else return(&quot;more than 0&quot;)
  }
  </code></pre>
  <p>Any help appreciated! Thanks in advance!</p>
  <p>Maxl</p>