1
我有一個簡單的閃亮應用程序,只是一個下拉列表阿富汗地區和傳單地圖相同。 來自shinyDashboard的infoBox/valueBox閃亮
形狀文件可以在這個link訪問 - 使用AFG_adm2.shp從http://www.gadm.org/download
這裏的應用代碼:
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
或valueBox
比如Widget從shinyDashboard到根據用戶選擇在地圖下方顯示一些數據(如地區人口)。我怎樣才能做到這一點?
不能一個閃亮的應用程序內進行? – ProgSnob
它可以是..你的閃亮應用程序需要的一些變化。例如你需要加載shinydashboard軟件包。嘗試以上鍊接 –
所以你的意思是我應該切換到shinydashboard? – ProgSnob