使用selectInput的闪亮仪表板和传单

时间:2018-12-27 12:09:20

标签: r shiny leaflet shinydashboard shiny-reactivity

我正在尝试将闪亮的仪表板与传单包装一起使用。我尝试在仪表板中使用“ SelectInput”功能基于所选的输入(geoArea)创建反应式地图。但是,我无法使传单和SelectInput彼此连接。

我还想在数据集中区分两组,并以传单/光泽的方式对其进行绘制(列名称“ up.and.down” 具有正值和负值)。在Base R中,我可以它使用了tidyverse包中的过滤器选项,并为每种颜色赋予了不同的颜色,但是我不确定这在Shinydashboard中如何工作。任何方面的帮助将不胜感激。

<h1>Search query</h1>
<b>k1</b>: val1<br>
<b>data</b>: test<br>

1 个答案:

答案 0 :(得分:0)

尝试这个:

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(leaflet)
library(tidyverse)


datafile<-read.csv("/Users/prabeshkc/Desktop/stackoverflow data.csv") %>% 
  mutate(color=ifelse(up.and.down<0,"red","blue"))

ui<- dashboardPage(
  skin = "blue",
  dashboardHeader(title = "Cluster Map"),
  dashboardSidebar(
    selectInput("Area",label = "Geo Area",
                choices = datafile$geoArea)
  ),
  dashboardBody(
    fluidRow(box(width = 12,leafletOutput(outputId = "mymap")))
  ))

server <- function(input, output) {

  output$mymap<- renderLeaflet({
    validate(need(datafile,"Add file"))
    validate(need(input$Area,"Select Area"))
    datafile %>% 
      filter(geoArea %in% input$Area) %>% 
      leaflet() %>% 
      addTiles() %>% 
      addCircleMarkers(lng = ~lng,lat = ~lat,color=~color,
                       popup = ~paste(paste0("Goals - ",goals),paste0("Achieved - ",achieved), sep="<br>"))
  })
}
shinyApp(ui = ui, server = server)