title: How do I make a reactive palette, which changes the colour of polygons on a map, when a different variable is selected in Shiny?
body: <p>This is my first question so I apologise if its not up to scratch, but I'm stuck on an issue and I really need help please. </p>
  
  <p>I'm trying to create a shiny app, which will allow you to select a species from a drop down menu, thereby changing the colour of country polygons on a map, 1 colour for presence and another for absence. I've created a sf object with the shapefile data and merged it with a presence absence (1 +0 respectively) dataframe, the intention being that selection of this species will change input$SppSelect, selecting a different column in the merged sf object, and then this will cause my leaflet map to be redrawn with a new species occurrence. </p>
  
  <p>To colour the map I intended to assign my species input variable to another variable: <code>sppcol &lt;- reactive({input$SppSel})</code>, and then use <code>Botpal &lt;- reactive({colorFactor(viridis(2), BotCon$sppcol())})</code> to make a reactive palette. I'd then use <code>fillColor = ~Botpal(Botcon$sspcol())</code> to change the colour of the polygons. </p>
  
  <p>I'm not sure if I can produce a reprex but I'll attempt to illustrate how the app should work. Palms = csv file with every species occurrence next to the country its in:</p>
  
  <p>( china : caryota mitis)</p>
  
  <p>(china : caryota no)</p>
  
  <p>(Bhutan : caryota mitis).</p>
  
  <p>BotCon is the botanical countries shape file I'm working with.
  :</p>
  
  <pre><code>ui &lt;- fluidPage(
  
    sidebarLayout(
      sidebarPanel(
        selectInput(inputId = "SppSel", 
                    label = "Species Selection",
                    choices = paste(Palms$SpecName)),
      ),
      mainPanel(
        leafletOutput("mymap", height=600)
      )))
  
  
  server &lt;- function(input, output) {
  
    PresAb &lt;- create.matrix(Palms, tax.name = "SpecName", locality = "Area_code_L3")
  
    PresAb.df &lt;- as.data.frame(t(PresAb))
  
    PresAb.dfnamed &lt;- cbind(LEVEL3_COD = rownames(PresAb.df), PresAb.df)
  
    jointdataset &lt;- merge(BotCon, PresAb.dfnamed, by = 'LEVEL3_COD', all.y=TRUE)
  
    sppcol &lt;- reactive({input$SppSel})
  
    Botpal &lt;- reactive({colorFactor(viridis(2), jointdataset$sppcol())})
  
  
    output$mymap &lt;- renderLeaflet({
      leaflet() %&gt;%
        addTiles() %&gt;%
        addPolygons(data=jointdataset, 
                    stroke = TRUE,smoothFactor = 0.3, weight = 1, fillOpacity = 0.5,  
                    fillColor = ~Botpal(jointdataset$"caryota mitis")
    }) }
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>My question is therefore; how can I use my species selection input, to select a different column of the merged dataset I've created, and colour my map polygons using the 1s and 0s present inside this column please? </p>
  
  <p>(really sorry for the layout, I'm pretty much self taught for all this stuff too) </p>