首页 > 解决方案 > 地图发回主动反应错误

问题描述

在 Shiny 上拼凑一张地图,但一直出错。当我使用 Leaflet 使用相同的步骤时,它运行良好,但是当我使用 mapview 时,它不会。不幸的是,我无法为可重现的示例提供数据,因为它涉及具有长度几何形状的整形文件。

library(sf)
library(shiny)
library(shinyWidgets)
library(dplyr)
library(leaflet)
library(mapdeck)

ui <- fluidPage(
  fluidRow(
    column(
      width = 10, offset = 1,
      tags$h3("Select Area"),
      panel(
        selectizeGroupUI(
          id = "my-filters",
          params = list(
            state = list(inputId = "state", title = "state:"),
            city = list(inputId = "city", title = "city:"),
            turf = list(inputId = "turf", title = "turf:")
          ))
      ),
      mapviewOutput(outputId = "mymap")
    )
  )
)

server <- function(input, output, session) {

  res_mod <- callModule(
    module = selectizeGroupServer,
    id = "my-filters",
    data = df,
    vars = c("state", "city", "turf")
  )

  output$box <- mapview::renderMapview({

    res <- res_mod()

    mapView(res)

  })

}

shinyApp(ui, server)

每当我运行它时,我都会遇到以下错误:

Warning: Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
  63: stop
  62: .getReactiveEnvironment()$currentContext
  61: getCurrentContext
  60: .dependents$register
  59: cheat
  52: server [#23]

标签: rshinyshiny-servershiny-reactivityr-mapview

解决方案


推荐阅读