带有传单的闪亮应用-反应功能不起作用

时间:2020-07-15 15:16:01

标签: r shiny leaflet

我已经开始使用Shiny软件包,但我的反应式功能有问题。目标是创建一个地图,该地图显示每个比利时省的posdif变量,并且可以对每个部门进行反应式查看(nace2d)。我得到一个反应式地图作为输出,但是数字,颜色和标签不正确。我玩过标签,垃圾桶和好朋友的位置,并试图使它们具有反应性,但是似乎没有任何作用...

ui <- fluidPage(
  sidebarLayout(position = 'right',
                sidebarPanel(
                  selectInput("nace2d","Sector",choices = c("45",'46',"47"),selected = "45"),
                  width = 2),
                mainPanel(leafletOutput("mymap",height = 650,width=605)))
  
  
)

# define server
server <- function(input,output, session){
  
  
  labels <- sprintf(
    "<strong>%s</strong><br/>%g jobcreatie",
    projects.df$label, projects.df$posdif
  ) %>% lapply(htmltools::HTML)
  

  bins <- c(0, 500,1000,1500,2000,2500,3000,3500,4000,4500,5000)
  pal <- colorBin("YlOrRd", domain = projects.df$posdif, bins = bins)
  
  
  df<-reactive({
    projects.df%>%
      dplyr::filter(nace2d %in% input$nace2d)
  })
  
  

  output$mymap <- renderLeaflet({
    leaflet(data=df()) %>%
      addTiles() %>%
      addPolygons(
        fillColor = ~pal(posdif), 
        label = labels,
        labelOptions = labelOptions(
          style = list("font-weight"))) %>%
      addLegend(pal = pal, values = ~posdif, opacity = 0.7, title = NULL,
                position = "bottomright")
    
  })
  
  
}

shinyApp(ui = ui, server = server)

0 个答案:

没有答案