title: How to prevent Shiny from crashing when only one observation is selected with layer_smooths?
body: <p>I have built a Shiny App that generates an interactive plot with <code>ggvis</code>. I have added <code>sliderInput</code> features that filter my data and the plot changes accordingly. I have also added the <code>layer_smooths</code> call to <code>ggvis</code> and the trend line adjusts dynamically as the user changes the <code>sliderInput</code> and filters the data. </p>
  
  <p>Unfortunately when the data is filtered so only one observation remains it isn't possible to create the trend line and Shiny crashes. Is there any way for me to augment the <code>layer_smooths</code> call so that if there is only one observation in the data set (after filtering) the call to <code>layer_smoooths</code> is ignored? If I remove the call to <code>layer_smooths</code> Shiny will not crash when only one observation is present but I very much want to keep the trend line functionality. </p>
  
  <p>I have recreated some example Shiny code to show the issue. After launching the app if you filter the <code>mpg</code> slider on the dashboard till only one observation remains the app will crash.</p>
  
  <pre><code>library(shiny)
  library(ggvis)
  library(dplyr)
  data(mtcars)
  
  server &lt;- function(input, output) {
  
      example &lt;- reactive({
              # set initial values
              minmpg &lt;- input$m[1]
              maxmpg &lt;- input$m[2]
  
              # apply filters
              mpg_example &lt;- mtcars %&gt;%
                      filter(
                              mpg &gt;= minmpg,
                              mpg &lt;= maxmpg)
              mpg_example &lt;- as.data.frame(mpg_example)})
  
      vis &lt;- reactive({
              example %&gt;%
                      ggvis(x = ~mpg, y = ~disp) %&gt;%
                      layer_points(size := 50) %&gt;% 
                      layer_smooths(span = 1.5)
      })
  
      vis %&gt;% bind_shiny("distPlot")
  }
  
  ui &lt;- fluidPage(
      sidebarLayout(
              sidebarPanel(
                      sliderInput("m", "mpg", 10, 
                                  33, value = c(10, 33), step = 1)),
              mainPanel(ggvisOutput("distPlot"))
      )
  )
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>Errors seen (with truncated stack traces):</p>
  
  <pre><code>Warning: Error in predLoess: NA/NaN/Inf in foreign function call (arg 5)
  Stack trace (innermost first):
      114: predLoess
      113: predict.loess
      112: stats::predict
      111: pred_grid.loess
      110: pred_grid
      109: compute_model_prediction.data.frame
      108: compute_model_prediction
  Warning: Error in predLoess: NA/NaN/Inf in foreign function call (arg 5)
  Stack trace (innermost first):
      62: &lt;Anonymous&gt;
      61: stop
      60: r_spec
      59: observerFunc
  </code></pre>