title: Display raster over shapefile in shiny R
body: <p>I am trying to display a raster over my shapefile in my shiny app. Here's my approach. </p>
  
  <pre><code># Load libraries and create sample data 
  
    library(raster)
    library(shiny)
    library(dplyr)
    library(leaflet)
    library(ggplot2)
    library(ggthemes)
    library(tmap)
  
    fr.shp &lt;- getData('GADM', country='FRA', level=1)
  
    coords &lt;- data.frame(coordinates(fr.shp))
    names(coords) &lt;- c('lon', 'lat')
    dat.df &lt;- expand.grid(lon = coords[, 1],
                          seasonID = c('winter', 'summer'),
                          business = c('train', 'bus', 'taxi'), 
                          variable = c('modP', 'modT'),
                          YearRef = 2001:2003)
  
    dat.df1 &lt;- coords %&gt;% dplyr::left_join(dat.df) %&gt;% dplyr::mutate(value = rnorm(n()))
  </code></pre>
  
  <p>Below is my shiny app that shows the values for a given combination of 
  seasonID, businees, variable and YearRef. The code that I have commented out was supposed
  to also plot the shapefile over which the raster should be plotted. However it is not working.</p>
  
  <pre><code>  ui &lt;- fluidPage(
          titlePanel('my shiny'),
            sidebarLayout(position = 'left',
                sidebarPanel(
                  selectInput(inputId = 'seasonRef', label = 'Select season', choices = c('winter','summer'), selected = 'Kharif'),
                  selectInput(inputId = 'transport', label = 'Select transport',
                              choices = c('train','bus','taxi'), selected = 'train'),
                  checkboxGroupInput(inputId = 'type', label = NULL, 
                                     choiceNames = c('modP','modT'),
                                     choiceValues = c('modP','modT'),
                                     width = '400px', selected = 'modP'),
                  sliderInput('yearRef','Select Year',min=2001,max=2003,value=1)
                  ),
  
                  mainPanel(
                    tabsetPanel(
                    tabPanel('myplots', plotOutput(outputId = 'rast')),
                    leafletOutput("my_tmap")
                  )
                  )
                )
            )
  
      server &lt;- function(input, output) {
  
          tempI &lt;- reactive({dat.df1 %&gt;% dplyr::filter(seasonID == input$seasonRef &amp;
                                                       business == input$transport &amp;
                                                       YearRef == input$yearRef &amp;
                                                       variable == input$type)})
  
          output$rast &lt;- renderPlot({
          ggplot() + geom_raster(data = tempI(), aes(x = lon, y = lat, fill = value)) +
          theme_map() + coord_equal() + scale_fill_viridis_c(option = 'C')
        })
  
          # tmap_mode("view")
          #  output$my_tmap = renderLeaflet({
          #    qtm(fr.shp)})
        }
  
  
        shinyApp(ui, server)
  </code></pre>
  
  <p>I show this question but this only lets a background shapefile to be used instead of my own shapefile.</p>
  
  <p><a href="https://stackoverflow.com/questions/34040625/overlaying-shapefiles-or-raster-over-interactive-maps">Overlaying shapefiles or raster over interactive maps</a></p>