Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.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_Shinyjs_R Leaflet_Shiny Reactivity - Fatal编程技术网

R 闪亮模块:从模块中的单个功能返回多个无功输出(链接传单地图和数据表)

R 闪亮模块:从模块中的单个功能返回多个无功输出(链接传单地图和数据表),r,shiny,shinyjs,r-leaflet,shiny-reactivity,R,Shiny,Shinyjs,R Leaflet,Shiny Reactivity,我正在编写一个闪亮的模块来链接传单地图和数据表(代码基于) 我遇到的困难是将一些渲染文本(“tabvec_title”)和数据表(“vector_table”)从module.R脚本传递到应用程序。R、 以及将资料表与单张地图连接起来。这条准则很有用(),但我仍然不清楚如何最好地将呈现的文本和表传递给app.R。非常感谢你的建议。(更新见下文评论) 文件摘录: app.R(第2版): source("module.R") tags$div(id="tabvec ", fluidRow(

我正在编写一个闪亮的模块来链接传单地图和数据表(代码基于)

我遇到的困难是将一些渲染文本(“tabvec_title”)和数据表(“vector_table”)从module.R脚本传递到应用程序。R、 以及将资料表与单张地图连接起来。这条准则很有用(),但我仍然不清楚如何最好地将呈现的文本和表传递给app.R。非常感谢你的建议。(更新见下文评论)

文件摘录: app.R(第2版):

source("module.R")

tags$div(id="tabvec ",
  fluidRow(
  column(12,
    tags$br(),
       tags$div(myModuleUI('vector_titab'), id="myModuleUI")


server <- function(input, output, session) {
proxy <- leafletProxy("map")

callModule(mod_sl1,'vector_titab', reactive(input$pow_sl), proxy, vector_table, tabvec_title, 
   reactive(input$map_marker_click))

# Hide/show DT and title beneath map
 observe({
   if(input$pow_sl == TRUE){
     shinyjs::show(id="myModuleUI", selector = input$pow_sl)
   } else {
     shinyjs::hide(id="myModuleUI", selector = input$pow_sl)
   }}
 )
   ...
# Permits interactive selection of marker and DT table rows ----
library(leaflet)
library(DT)
library(shinydashboard)

myModuleUI <- function(id){
  ns <- NS(id)
  tagList(
    textOutput(ns("tabvec_title")),
    DT::dataTableOutput(ns("vector_table"))
  )
}

mod_sl1 <- function(input, output, session, pow_sl, prox, vector_table, tabvec_title, 
                map_marker_click){

 ns <- session$ns
 observeEvent(pow_sl(), {
 html_legend <- '<i class="fa fa-map-marker" style="color:green;"></i></i>Plants '
 print("test89")
 if(pow_sl() != 0){
    pow_sl <- readOGR("./geospatial_files/srilanka", layer = "plants")
    pow_sldf <- as.data.frame(pow_sl)

    # add table
    pow_d <- pow_sldf[,c(1:5,7:8,10:11,14)]
    pow_d$Latitude <- round(pow_d$Latitude, digits=4)
    pow_d$Longitude <- round(pow_d$Longitude, digits=4)
    colnames(pow_d)<- c("id","PlantName","Latitude", "Longitude","Type")
    pow_d$id <- as.character(pow_d$id)
    pow_d$Fuel <- as.character(pow_d$Fuel)
    pow_d$Type <- as.character(pow_d$Type)

    # drop first row with missing details
    pow_dt <- pow_d[-1,]

 output$tabvec_title <- renderText({ "Plants" })

 output$vector_table <- renderDataTable({
 DT::datatable(pow_dt, selection = c("single"),
                options=list(stateSave = TRUE, buttons = c('copy', 'csv', 'excel',  'print'),dom = 'Bflit'),
                rownames=FALSE, caption = "", extensions = 'Buttons')
})

 # to keep track of previously selected row
 prev_row <- reactiveVal()

 # new icon style
 red_icon = makeAwesomeIcon(icon = 'flag', markerColor = 'red', iconColor = 'white')

 observeEvent(input$vector_table_rows_selected, {
   row_selected = pow_dt[input$vector_table_rows_selected,]
   prox %>%
     addAwesomeMarkers(
      layerId = as.character(row_selected$id),
      lng=row_selected$Longitude,
      lat=row_selected$Latitude,
      group = "pow_slg",
      icon = red_icon,
      label = as.character(row_selected$Fuel))

   # Reset previously selected marker
   if(!is.null(prev_row()))
   {
    prox %>%
      addAwesomeMarkers(popup=as.character(prev_row()$Fuel),
                        layerId = as.character(prev_row()$id),
                        lng=prev_row()$Longitude,
                        lat=prev_row()$Latitude,
                        group = "pow_slg",
                        icon=icons_pow,
                        #icon = as.character(prev_row()$icons),
                        label = as.character(row_selected$Fuel))
  }
  # set new value to reactiveVal
  prev_row(row_selected)
  print("prev_row")
  print(prev_row)
})

prox %>%
  addControl(html = html_legend, position = "bottomleft", layerId="pow_slc") %>%
  addAwesomeMarkers(
    data = pow_dt, 
    layerId = as.character(pow_dt$id),
    icon = icons_pow,
    group = "pow_slg",
    label = as.character(pow_dt$Fuel))

    observeEvent(map_marker_click(), {
    clickId <- map_marker_click()$id
    dataTableProxy("vector_table") %>%
    selectRows(which(pow_dt$id == clickId)) %>%
    selectPage(which(input$vector_table_rows_all == clickId) %/% input$vector_table_state$length + 1)
})

 } else {
  prox %>% clearGroup("pow_slg") %>% removeControl(layerId="pow_slc")
}
})
}
源代码(“module.R”)
标记$div(id=“tabvec”,
fluidRow(
第(12)栏,
标记$br(),
标记$div(myModuleUI('vector_titab'),id=“myModuleUI”)

服务器我已经更新了上面的代码,该代码现在显示地图下方的数据表。但是,还有一个问题:当在表中选择一行突出显示地图标记时,我无法解决如何在地图上选择一个标记,然后突出显示DT表中的相应行。如果有更好的编码方法我很乐意学习。更新到现在解决上面选择标记和突出显示表中记录的问题。一切似乎都正常,但有兴趣了解是否有其他或更好的方法将模块链接到主应用程序。R。