Shiny 根据输入更改托盘值(光泽和传单)

Shiny 根据输入更改托盘值(光泽和传单),shiny,leaflet,Shiny,Leaflet,我用的是传单和闪亮的。我想根据可以通过输入更改的列为标记着色。几乎和我的一样。在本例中,用户可以更改调色板。在我的示例中,我想更改应用调色板的列。 我正在尝试使用类似于: fillColor = ~pal(!!sym(input$col_to_apply)) # input$col_to_apply is a column name (string) I want to use 然而,这不起作用。我也不确定在这种情况下是否必须使用reactive()。当然。我的建议是在创建调色板之前完成。调色

我用的是传单和闪亮的。我想根据可以通过输入更改的列为标记着色。几乎和我的一样。在本例中,用户可以更改调色板。在我的示例中,我想更改应用调色板的列。 我正在尝试使用类似于:

fillColor = ~pal(!!sym(input$col_to_apply)) # input$col_to_apply is a column name (string) I want to use

然而,这不起作用。我也不确定在这种情况下是否必须使用
reactive()

当然。我的建议是在创建调色板之前完成。调色板已经够棘手的了。请参见下面的示例:

library(leaflet)
library(maps)
library(shiny)

ui <- fluidPage(

    leafletOutput("map_1"),

    selectInput(inputId = "input_species", label = "Species Selection", choices = c("Species_1", "Species_2", "Species_3"))

)


server <- function(input, output, session) {

    #Load a map of the US from the 'map' package (runs once when apps starts)
    shp_map = map("state", fill = TRUE, plot = FALSE)

    #Make up a dataframe with some data for three species for each state (runs once when apps starts)
    df_data <- data.frame(state = unique(shp_map$names), Species_1 = sample(100:199, 63), Species_2 = sample(200:299, 63), Species_3 = sample(300:399, 63))

    #Create map
    output$map_1 <- renderLeaflet({

        df_map <- df_data

        #Create a column called species selected based on which is selected in the dropdown box
        df_map$Species_Selected <- df_map[, paste(input$input_species)]

        #Create a palette function
        palette <- colorNumeric(palette = "Blues", domain = df_map$Species_Selected)

        #Use the palette function created above to add the appropriate RGB value to our dataframe
        df_map$color <- palette(df_map$Species_Selected)

        #Create map
        map_1 <- leaflet(data = shp_map) %>% 

            addPolygons(fillColor = df_map$color, fillOpacity = 1, weight = 1, color = "#000000", popup = paste(sep = "", "<b>", paste(shp_map$names), " ", "</b><br>", df_map$Species_Selected)) 

        map_1

    })

}

shinyApp(ui, server)
图书馆(传单)
图书馆(地图)
图书馆(闪亮)
用户界面