2017-02-21 5 views
1

Ich habe eine einfache shiny-app mit nur einer Dropdown-Liste von Distrikten von Afghanistan und einer Flugblatt-Karte derselben. enter image description hereinfoBox/valueBox von shinyDashboard in shiny

kann die Form-Datei an diesem link zugegriffen werden - mit AFG_adm2.shp von http://www.gadm.org/download

hier ist der Code App: von infoBox oder valueBox wie Widgets

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) 

Ich möchte ein shinyDashboard zu Zeigen Sie einige Daten (z. B. Bezirkspopulation) unter der Karte basierend auf der Benutzerauswahl an. Wie kann ich das machen?

Antwort

1

Sie müssen die Struktur des Programms ändern und eine Dashboard-Seite in der Benutzeroberfläche hinzufügen.

Hier sind einige Referenzen, nur um zu sehen. du wirst es kennen lernen !!!

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

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

+0

es innerhalb einer glänzenden App getan werden kann, nicht wahr? – ProgSnob

+0

Es kann sein .. einige der Änderungen in Ihrer glänzenden App benötigt. Zum Beispiel müssen Sie shinydashboard Paket laden. probier oben links –

+0

Also meinst du ich sollte auf shinydashboard wechseln? – ProgSnob

Verwandte Themen