Ich habe eine einfache shiny-app mit nur einer Dropdown-Liste von Distrikten von Afghanistan und einer Flugblatt-Karte derselben. infoBox/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?
es innerhalb einer glänzenden App getan werden kann, nicht wahr? – ProgSnob
Es kann sein .. einige der Änderungen in Ihrer glänzenden App benötigt. Zum Beispiel müssen Sie shinydashboard Paket laden. probier oben links –
Also meinst du ich sollte auf shinydashboard wechseln? – ProgSnob