title: R Shiny app closes by itself after a while when running from R Studio, but it's still listening... is this normal?
body: <p>Generic question about R Shiny/R Studio...</p>
  <p>I've noticed that when I run my R Shiny app, everything I've programmed so far works as intended. However, if I keep the window open in the background and switch to using something else (i.e. Excel, Chrome, etc.), or sometimes even if I'm on the window itself, after a few minutes or so the window just closes by itself. However R Studio shows that it is still listening, and it won't run further code until I press the STOP button to terminate the existing run of the app.</p>
  <p>Is this behavior normal in R Studio when developing the app, or does it suggest that there's something wrong with my code that's causing it to disappear? There are no warning messages that appear in the console when it disappears. I've tried running another app using some basic example code I found, and the same thing happens.</p>
  <p>If this is a common thing, why does it do that and is there any way to stop this?</p>
  <p>Example code probably isn't relevant, but here is an example app from the RStudio website <a href="https://shiny.rstudio.com/articles/basics.html" rel="nofollow noreferrer">https://shiny.rstudio.com/articles/basics.html</a>. This issue occurs with this app too.</p>
  <pre><code>ui &lt;- fluidPage(
    
    # App title ----
    titlePanel(&quot;Reactivity&quot;),
    
    # Sidebar layout with input and output definitions ----
    sidebarLayout(
      
      # Sidebar panel for inputs ----
      sidebarPanel(
        
        # Input: Text for providing a caption ----
        # Note: Changes made to the caption in the textInput control
        # are updated in the output area immediately as you type
        textInput(inputId = &quot;caption&quot;,
                  label = &quot;Caption:&quot;,
                  value = &quot;Data Summary&quot;),
        
        # Input: Selector for choosing dataset ----
        selectInput(inputId = &quot;dataset&quot;,
                    label = &quot;Choose a dataset:&quot;,
                    choices = c(&quot;rock&quot;, &quot;pressure&quot;, &quot;cars&quot;)),
        
        # Input: Numeric entry for number of obs to view ----
        numericInput(inputId = &quot;obs&quot;,
                     label = &quot;Number of observations to view:&quot;,
                     value = 10)
        
      ),
      
      # Main panel for displaying outputs ----
      mainPanel(
        
        # Output: Formatted text for caption ----
        h3(textOutput(&quot;caption&quot;, container = span)),
        
        # Output: Verbatim text for data summary ----
        verbatimTextOutput(&quot;summary&quot;),
        
        # Output: HTML table with requested number of observations ----
        tableOutput(&quot;view&quot;)
        
      )
    )
  )
  
  # Define server logic to summarize and view selected dataset ----
  server &lt;- function(input, output) {
    
    # Return the requested dataset ----
    # By declaring datasetInput as a reactive expression we ensure
    # that:
    #
    # 1. It is only called when the inputs it depends on changes
    # 2. The computation and result are shared by all the callers,
    #    i.e. it only executes a single time
    datasetInput &lt;- reactive({
      switch(input$dataset,
             &quot;rock&quot; = rock,
             &quot;pressure&quot; = pressure,
             &quot;cars&quot; = cars)
    })
    
    # Create caption ----
    # The output$caption is computed based on a reactive expression
    # that returns input$caption. When the user changes the
    # &quot;caption&quot; field:
    #
    # 1. This function is automatically called to recompute the output
    # 2. New caption is pushed back to the browser for re-display
    #
    # Note that because the data-oriented reactive expressions
    # below don't depend on input$caption, those expressions are
    # NOT called when input$caption changes
    output$caption &lt;- renderText({
      input$caption
    })
    
    # Generate a summary of the dataset ----
    # The output$summary depends on the datasetInput reactive
    # expression, so will be re-executed whenever datasetInput is
    # invalidated, i.e. whenever the input$dataset changes
    output$summary &lt;- renderPrint({
      dataset &lt;- datasetInput()
      summary(dataset)
    })
    
    # Show the first &quot;n&quot; observations ----
    # The output$view depends on both the databaseInput reactive
    # expression and input$obs, so it will be re-executed whenever
    # input$dataset or input$obs is changed
    output$view &lt;- renderTable({
      head(datasetInput(), n = input$obs)
    })
    
    
  }
  shinyApp(ui, server)
  </code></pre>