Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何访问使用输入传递的传单地图?_R_Shiny_Leaflet_R Leaflet - Fatal编程技术网

R 如何访问使用输入传递的传单地图?

R 如何访问使用输入传递的传单地图?,r,shiny,leaflet,r-leaflet,R,Shiny,Leaflet,R Leaflet,在我的示例中,我需要从模块2(嵌套)访问传单地图,并在地图上使用输入$返回多边形坐标。当我在我的主模块(模块1)中这样做时,它工作得非常好,我可以自由地参考“地图”。不幸的是,当我将map传递给另一个模块(模块2)时,input$的相同技巧根本不起作用。你知道怎么解决吗 这是一个可复制的例子。请在地图上画一个矩形,并确保没有坐标返回到文本区域。但是,如果您取消注释我的格雷码(在模块1中),那么您将看到所有工作正常 library(shiny) library(mapboxer) library(

在我的示例中,我需要从模块2(嵌套)访问
传单
地图,并在地图上使用
输入$
返回多边形坐标。当我在我的主模块(模块1)中这样做时,它工作得非常好,我可以自由地参考“地图”。不幸的是,当我将map传递给另一个模块(模块2)时,
input$
的相同技巧根本不起作用。你知道怎么解决吗

这是一个可复制的例子。请在地图上画一个矩形,并确保没有坐标返回到文本区域。但是,如果您取消注释我的格雷码(在模块1中),那么您将看到所有工作正常

library(shiny)
library(mapboxer)
library(dplyr)
library(sf)
library(leaflet)
library(leaflet.extras)


moduleServer <- function(id, module) {
  callModule(module, id)
}

# UI 1 #
mod_btn_UI1 <- function(id) {
  
  ns <- NS(id)
  tagList(
    leafletOutput(ns("map")),
    mod_btn_UI2(ns("other")),
    verbatimTextOutput(ns("selectedArea1"))    
  )
}

# Server 1 #
mod_btn_server1 <- function(id){
  moduleServer(id, function(input, output, session) {
    
    ns <- NS(id)
        
    coords <- quakes %>%
      sf::st_as_sf(coords = c("long","lat"), crs = 4326)
    
    output$map <- leaflet::renderLeaflet({
      leaflet::leaflet() %>% 
        leaflet::addTiles() %>% 
        leaflet::setView(172.972965,-35.377261, zoom = 4) %>%
        leaflet::addCircleMarkers(
          data = coords,
          stroke = FALSE,
          radius = 6) %>% 
        leaflet.extras::addDrawToolbar()
    })
    
    # here I pass map id and session to module 2 and it works fine
    mod_btn_server2("other", "map", session)  
    
    # # the code below works fine - here I simply pass 'map' to input$
    #
    # polygon_coords <- reactive({input$map_draw_new_feature$geometry$coordinates[[1]]})
    # output$selectedArea1 <- renderPrint({
    #   print(polygon_coords())
    # })           
  })
}


# UI 2 #
mod_btn_UI2 <- function(id) {
  
  ns <- NS(id)
  tagList(
    verbatimTextOutput(ns("selectedArea2"))
  )
}

# Server 2 #
mod_btn_server2 <- function(id, mapPassed, parentSession){
  moduleServer(id, function(input, output, session) {
    
    ns <- NS(id)
   
  # here input seems not working with 'mapPassed' as it does in module 1   
  polygon_coords <- reactive({input$mapPassed_draw_new_feature$geometry$coordinates[[1]]})
    
     output$selectedArea2 <- renderPrint({
       print(polygon_coords())
     
   })
  })
}


# Final app #

ui <- fluidPage(  
  tagList(
    mod_btn_UI1("test-btn"))  
)

server <- function(input, output, session) {  
  mod_btn_server1("test-btn")  
}

shinyApp(ui = ui, server = server)

库(闪亮)
图书馆(mapboxer)
图书馆(dplyr)
图书馆(sf)
图书馆(单张)
图书馆(单张、附加资料)

moduleServer当您使用这种模块化时,输入、输出和会话模块参数是主输入/输出/会话的子集,对应于从模块id(NS函数)创建的名称空间。如果在id为foo的模块中创建名为dummy的输入,那么真正创建的是名为foo dummy的输入。因此,在foo模块中,您可以将名称以“foo-”开头的所有输入和类似地以“foo-”开头的所有输出作为输入,而不是将输入名称传递给嵌入式模块,您可以将其作为响应传递:

mod_btn_server2(“其他”,
被动(输入$map\u draw\u new\u功能$geometry$坐标[[1]]),
(会议)
您可以在嵌入式模块中像其他任何反应式模块一样使用它:


polygon\u coords好的,我试着想象一下您在考虑我的示例时写的内容,但仍然不知道是否可以在传递的映射上使用
input
。我通过的地图在
proxy
中运行良好。我传递的映射引用了模块1中的名称空间。你能给我举个例子,我应该如何正确地实现它吗?非常好而且棘手的解决方案,非常感谢!