Shiny 在不重新绘制传单地图的情况下进行闪亮的UI调整 问题

Shiny 在不重新绘制传单地图的情况下进行闪亮的UI调整 问题,shiny,leaflet,shinydashboard,Shiny,Leaflet,Shinydashboard,我正在创建一个shinydashboard来帮助客户探索一些空间数据。我希望实现的UI设计允许用户轻松地在两种布局之间切换: 仅地图 地图+数据表 我在实现此设计时遇到困难,因为每次用户在布局之间切换时,都会出现两个问题: 地图被重新绘制 操作按钮断开,阻止用户浏览数据 我的猜测是,这可能是一个名称空间问题,但我没有任何创建的经验(看起来复杂而可怕) 有人有解决这些问题的好策略吗 可复制示例: 我重新编写了你的应用程序,因此它使用了@daattali的优秀软件包。我还删除了一些格式,只是为了

我正在创建一个shinydashboard来帮助客户探索一些空间数据。我希望实现的UI设计允许用户轻松地在两种布局之间切换:

  • 仅地图
  • 地图+数据表
我在实现此设计时遇到困难,因为每次用户在布局之间切换时,都会出现两个问题:

  • 地图被重新绘制
  • 操作按钮断开,阻止用户浏览数据
  • 我的猜测是,这可能是一个名称空间问题,但我没有任何创建的经验(看起来复杂而可怕)

    有人有解决这些问题的好策略吗

    可复制示例:
    我重新编写了你的应用程序,因此它使用了@daattali的优秀软件包。我还删除了一些格式,只是为了缩短它

    最终,我们可以使用
    javascript
    hide
    show
    方法来隐藏包含表的框

    还请注意,我已将您的地图和表格移动到
    ui

    library(dplyr)
    library(shiny)
    library(shinydashboard)
    library(leaflet)
    library(RColorBrewer)
    library(DT)
    library(shinyjs)
    
    header <- dashboardHeader(
      title = "Example"
    )
    
    sidebar <- dashboardSidebar(
      sidebarMenu(id="tabs",
                  checkboxInput(inputId = "show",label = "Show Data Table",value = TRUE),
                  p(),
                  actionButton("zoom","Zoom to Oz", icon = icon("search-plus")
                               )
                  )
      )
    
    body <- dashboardBody(
    
      ## Initialise shinyjs
      useShinyjs(),
    
      div(id = "box_table-outer",
        box(id = "box_table",
          title = "",
          width = 12,
          height = "100%",
          DT::dataTableOutput("table")
          )
        ),
      box(title = "",
          width = 12,
          height = "100%",
          leafletOutput("map",
                        height = "600px")
          )
      )
    
    ui <- dashboardPage(header, sidebar, body)        
    
    server <- function(input, output) {
    
      output$map <- renderLeaflet({
    
        pal <- colorNumeric("Set2", quakes$mag)
    
        leaflet(quakes) %>% 
          addTiles() %>%
          fitBounds(~min(long), ~min(lat), ~max(long), ~max(lat)) %>% 
          addCircles(radius = ~10^mag/10, weight = 1, color = "#777777",
                     fillColor = ~pal(mag), fillOpacity = 0.7, popup = ~paste(mag)
          )
      })
    
      output$table <- DT::renderDataTable({
        quakes %>% 
          select(lat,long,mag) %>% 
          DT::datatable()
      })
    
    
      observeEvent(input$zoom, {
    
        leafletProxy(mapId = "map",data = quakes$mag) %>% 
          setView(132.166667, -23.033333,  zoom = 4)
    
      })
    
      ## use shinyjs functions to show/hide the table box 
      ## dependant on the check-box
      observeEvent(input$show, {
        if(input$show){
          show(id = "box_table-outer")
        }else{
          hide(id = "box_table-outer")
        }
      })
    
    }
    
    shinyApp(ui,server)
    
    库(dplyr)
    图书馆(闪亮)
    图书馆(shinydashboard)
    图书馆(单张)
    图书馆(RColorBrewer)
    图书馆(DT)
    图书馆(shinyjs)
    
    标题你所说的“动作按钮断裂”是什么意思?它是如何断裂的。当我运行你的代码时,动作按钮总是有效的?嗯,这很有趣。当我运行代码时,点击复选框后ActionButton(“Zoom to Oz”)停止运行。这似乎是一个好方法,但我不确定我是否能用它实现我的UI设计(即并排两列)。你能想出一种方法来设置用户界面,使这些元素显示在两列中,当表格被隐藏时,地图列将展开以填充空间吗?@Tiernan啊,好问题。目前我不确定我是否有解决办法
    > sessionInfo()
    R version 3.2.3 (2015-12-10)
    Platform: x86_64-apple-darwin13.4.0 (64-bit)
    Running under: OS X 10.11.3 (El Capitan)
    
    locale:
    [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    
    attached base packages:
    [1] stats     graphics  grDevices utils     datasets 
    [6] methods   base     
    
    other attached packages:
    [1] dplyr_0.4.3          shinydashboard_0.5.1
    [3] DT_0.1.39            RColorBrewer_1.1-2  
    [5] leaflet_1.0.1.9003   shiny_0.13.1        
    
    loaded via a namespace (and not attached):
     [1] Rcpp_0.12.3        magrittr_1.5       munsell_0.4.3     
     [4] colorspace_1.2-6   xtable_1.8-2       R6_2.1.2          
     [7] plyr_1.8.3         tools_3.2.3        parallel_3.2.3    
    [10] DBI_0.3.1          htmltools_0.3      lazyeval_0.1.10   
    [13] yaml_2.1.13        digest_0.6.9       assertthat_0.1    
    [16] htmlwidgets_0.6    rsconnect_0.4.1.11 mime_0.4          
    [19] scales_0.4.0       jsonlite_0.9.19    httpuv_1.3.3 
    
    library(dplyr)
    library(shiny)
    library(shinydashboard)
    library(leaflet)
    library(RColorBrewer)
    library(DT)
    library(shinyjs)
    
    header <- dashboardHeader(
      title = "Example"
    )
    
    sidebar <- dashboardSidebar(
      sidebarMenu(id="tabs",
                  checkboxInput(inputId = "show",label = "Show Data Table",value = TRUE),
                  p(),
                  actionButton("zoom","Zoom to Oz", icon = icon("search-plus")
                               )
                  )
      )
    
    body <- dashboardBody(
    
      ## Initialise shinyjs
      useShinyjs(),
    
      div(id = "box_table-outer",
        box(id = "box_table",
          title = "",
          width = 12,
          height = "100%",
          DT::dataTableOutput("table")
          )
        ),
      box(title = "",
          width = 12,
          height = "100%",
          leafletOutput("map",
                        height = "600px")
          )
      )
    
    ui <- dashboardPage(header, sidebar, body)        
    
    server <- function(input, output) {
    
      output$map <- renderLeaflet({
    
        pal <- colorNumeric("Set2", quakes$mag)
    
        leaflet(quakes) %>% 
          addTiles() %>%
          fitBounds(~min(long), ~min(lat), ~max(long), ~max(lat)) %>% 
          addCircles(radius = ~10^mag/10, weight = 1, color = "#777777",
                     fillColor = ~pal(mag), fillOpacity = 0.7, popup = ~paste(mag)
          )
      })
    
      output$table <- DT::renderDataTable({
        quakes %>% 
          select(lat,long,mag) %>% 
          DT::datatable()
      })
    
    
      observeEvent(input$zoom, {
    
        leafletProxy(mapId = "map",data = quakes$mag) %>% 
          setView(132.166667, -23.033333,  zoom = 4)
    
      })
    
      ## use shinyjs functions to show/hide the table box 
      ## dependant on the check-box
      observeEvent(input$show, {
        if(input$show){
          show(id = "box_table-outer")
        }else{
          hide(id = "box_table-outer")
        }
      })
    
    }
    
    shinyApp(ui,server)