在使用 Shiny using 处理地图时mapview
,我一直被反应式弄糊涂,并试图让我的地图动态更新。这是一个无法正常工作的可重现示例,尽管是使用其他 SO 答案中的原则设计的:
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(sf)
library(mapview)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Test of Mapview Selective Viewing"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("county", "County Name",
choices = c("All", levels(franconia$NAME_ASCI)),
selected = "All"
)
),
# Show a plot of the generated distribution
mainPanel(
mapviewOutput("mapPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
fran <- reactive({
f <- franconia
if(input$county != "All") f <- franconia %>% filter(NAME_ASCI == input$county)
f
})
output$mapPlot <- renderMapview({
#get the data
f <- isolate(fran())
#generate a map
mapview(f, zcol = "NAME_ASCI")
})
}
# Run the application
shinyApp(ui = ui, server = server)
这有效,但地图不会更新。我已经尝试放入一个操作按钮 - 并将 input$button 放在隔离语句之前,但是,这会导致整个事情抛出一个错误。
我想查看所有内容或查看单个县。
关于这里缺少/错误的任何想法?我对闪亮和处理反应物有点陌生!