在可拖动的Shiny面板中平移传单图或Plotly图也会移动面板

时间:2019-06-10 18:53:12

标签: shiny r-plotly r-leaflet

在可拖动的Shiny面板(例如,带有draggable = T的absolutePanel)中使用传单地图时,用鼠标平移传单地图也会拖动Shiny面板。

有没有一种方法可以防止用鼠标平移地图同时移动“发光”面板?

我认为这类似于已解决的问题: https://github.com/rstudio/shiny/issues/711

并且有与单张中的点击传播相关的DOM事件函数。

编辑:

在Plotly图中也会发生这种情况,这可能是一个比我最初意识到的更为普遍的问题。该问题已被编辑为包括密谋。

传单示例:

library(leaflet)
library(shiny)

shinyApp(
  ui = fluidPage(
    absolutePanel(draggable=T, width='600px', wellPanel(
        fluidRow(leafletOutput('map'))
    ))
  ),
  server = function(input, output, session) {
    output$map=renderLeaflet({
      leaflet() %>%
      addProviderTiles(providers$OpenStreetMap)
    }) 
  }
)

在传单中将拖动选项设置为F可解决此问题,但会使地图的用处不大。

shinyApp(
  ui = fluidPage(
    absolutePanel(draggable=T, width='600px', wellPanel(
        fluidRow(leafletOutput('map'))
    ))
  ),
  server = function(input, output, session) {
    output$map=renderLeaflet({
      leaflet(options=leafletOptions(dragging=F)) %>%
      addProviderTiles(providers$OpenStreetMap)
    }) 
  }
)

情节示例

缩放,平移和选择图交互都将导致可拖动面板移动。

library(plotly)
library(shiny)

shinyApp(
  ui = fluidPage(
    absolutePanel(draggable=T, width='600px', wellPanel(
        fluidRow(plotlyOutput('plot'))
    ))
  ),
  server = function(input, output, session) {
    output$plot=renderPlotly({
      plot_ly(data=mtcars, type='scatter', mode='markers', x=~hp, y=~mpg, name=~cyl)
    })
  }
)

0 个答案:

没有答案
相关问题