2017-02-21 5 views
1

아프가니스탄의 지구 및 동일한 리플렛지도가있는 드롭 다운 목록이있는 간단한 반짝이 앱이 있습니다. enter image description here반짝 반짝 빛나는 shinyDashboard의 infoBox/valueBox

모양 파일이 link에 액세스 할 수 있습니다 - 여기에 응용 프로그램 코드의 http://www.gadm.org/download

에서 AFG_adm2.shp를 사용하여 :

library(shiny) 
library(leaflet) 
library(rgdal) 
library(sp) 

afg <- readOGR(dsn = "data", layer ="AFG_adm2", verbose = FALSE, stringsAsFactors = FALSE) 

ui <- fluidPage(
    titlePanel("Test App"), 
    selectInput("yours", choices = c("",afg$NAME_2), label = "Select Country:"), 
    leafletOutput("mymap") 

) 

server <- function(input, output){ 
    output$mymap <- renderLeaflet({ 
    leaflet(afg) %>% addTiles() %>% 
     addPolylines(stroke=TRUE, color = "#00000", weight = 1) 
    }) 
    proxy <- leafletProxy("mymap") 

    observe({ 
    if(input$yours!=""){ 
     #get the selected polygon and extract the label point 
     selected_polygon <- subset(afg,afg$NAME_2==input$yours) 
     polygon_labelPt <- [email protected][[1]]@labpt 

     #remove any previously highlighted polygon 
     proxy %>% removeShape("highlighted_polygon") 

     #center the view on the polygon 
     proxy %>% setView(lng=polygon_labelPt[1],lat=polygon_labelPt[2],zoom=7) 

     #add a slightly thicker red polygon on top of the selected one 
     proxy %>% addPolylines(stroke=TRUE, weight = 2,color="red",data=selected_polygon,layerId="highlighted_polygon") 
    } 
    }) 
} 

# Run the application 
shinyApp(ui = ui, server = server) 

내가 원하는는 infoBox하거나을 shinyDashboard 에서 위젯 같은 valueBox 사용자 선택에 따라지도 아래에 일부 데이터 (예 : 지역 인구)를 표시합니다. 어떻게해야합니까?

답변

1

프로그램의 구조를 변경해야하며 UI에 대시 보드 페이지를 추가해야합니다.

다음은 일부 참조 정보입니다. 너는 알게 될 것이다 !!!

https://rstudio.github.io/shinydashboard/structure.html

https://rdrr.io/cran/shinydashboard/man/valueBox.html

+0

이 반짝이는 응용 프로그램 내에서 수행 할 수 없습니다? – ProgSnob

+0

반짝 이는 응용 프로그램에서 필요한 변경 사항 중 일부가 될 수 있습니다. 예를 들어 shinydashboard 패키지를로드해야합니다. 위의 링크를 시도하십시오 –

+0

그래서 내가 shinydashboard로 전환해야한다는 건가요? – ProgSnob

관련 문제