title: Shiny Map - Leaflet: How to select input matrix dynamically?
body: <p>I am trying to create a shiny app to generate dynamic maps. I want to use selectInput function to select matrix dynamically. I will integrate these maps in a Rmarkdown file where several apps are already there.</p>
  
  <p>I am using Amazon ec2 Ubuntu machine for hosting my shiny apps and rstudio. All the working apps are at /srv/shiny-server.</p>
  
  <p>I am getting following error:<br>
  <strong>Error</strong></p>
  
  <blockquote>
    <p>Error in maptab[, "long"] : incorrect number of dimensions
    Error in data.frame(lng = maptab[, "long"], lat = maptab[, "lat"], category = factor(maptab[,  : 
      object 'maptab' not found</p>
  </blockquote>
  
  <p><strong>Code</strong>  </p>
  
  <pre><code>### Top Doctors Map Leaflet
  library(shiny)
  library(leaflet)
  
  ##```{r, echo=FALSE, warning=FALSE, message=FALSE}
  r_colors &lt;- rgb(t(col2rgb(colors()) / 255))
  names(r_colors) &lt;- colors()
  
  shinyApp(
    ui =shinyUI(fluidPage(
  
      # Sidebar with a slider input for number of bins
      sidebarPanel(
        selectInput("var", "1, Select the variables from top doc summary file", 
                    choices =c( "top_docs" = 1, 
                                "docs" = 2,
                                "orgs" = 3, 
                                "phys_summ" = 4, 
                                "pm" = 5), selected= 1 ),
        br(),
        sliderInput("bins", "2, Select the number of BINs for Map", min = 40, max = 100000, value=20),
        br(),
        # radioButtons("color", "3, Select the color of histogram", choices =c("Green", "Red", "Yellow"), selected= "Green")
      ),
      # Show a plot of the generated distribution
      mainPanel(
        tabsetPanel(type = "tabs", 
                    tabPanel('Leaflet Map', leafletOutput("leaflet_map")),
                    tabPanel('Circular Map', leafletOutput("circular_map"))
        )))),
    server = shinyServer(function(input, output) {
      output$leaflet_map &lt;- renderLeaflet({
        maptab &lt;- input$var
        m &lt;- leaflet() %&gt;%
          addTiles() %&gt;%  # Add default OpenStreetMap map tiles
          addMarkers(lng=maptab[,long], lat=maptab[,lat],popup=maptab[,name])
        m  # Print the map
      })
      output$circular_map &lt;- renderLeaflet({
        ### Top Doctors circular map
  
        m = leaflet() %&gt;% addTiles()
        df = data.frame(
          lng=maptab[,'long'], 
          lat=maptab[,'lat'],
          # size = runif(40, 5, 20),
          category = factor(maptab[,'state']),
          color = sample(colors(), 40)
        )
        m = leaflet(df) %&gt;% addTiles()
        m %&gt;% addCircleMarkers(radius = runif(40, 4, 10), color = c('red','blue','green'))
      })
    }), 
    options = list(height = 480, width = 1050, dpi=200)
  
  )
  ##
  </code></pre>
  
  <p><strong>Sample Data input</strong></p>
  
  <pre><code>library(data.table)
  top_docs = data.table(long = runif(40, -87, -80), lat = runif(40, 25, 42), name = letters, state= letters) 
  docs = data.table(long = runif(9123, -87, -80), lat = runif(40, 25, 42), name = letters, state= letters) 
  orgs = data.table(long = runif(722, -87, -80), lat = runif(40, 25, 42), name = letters, state= letters) 
  phys_summ = data.table(long = runif(9845, -87, -80), lat = runif(40, 25, 42), name = letters, state= letters) 
  pm = data.table(long = runif(99999, -87, -80), lat = runif(40, 25, 42), name = letters, state= letters) 
  </code></pre>