rCharts - Shiny 中的传单和 nvd3 之间的冲突

标签 r leaflet shiny rcharts nvd3.js

我试图在同一个 Shiny 的页面中同时包含传单 map 和 nvd3 rCharts 图。
当我这样做时,传单不再显示我以前在 map 上显示的圆圈/POI(但不包括 nvd3)。
我怀疑这是一个 JS/CSS 冲突,因为当我尝试将它们单独包含时,它工作得很好。

一旦我启动“runapp”并查看 html 代码,我可以看到包含传单和 nvd3 时的唯一区别是正在使用的库:

 <link href="nvd3/css/nv.d3.css" rel="stylesheet"/>
<link href="nvd3/css/rNVD3.css" rel="stylesheet"/>
<script src="nvd3/js/d3.v3.min.js" type="text/javascript"></script>
<script src="nvd3/js/nv.d3.min-new.js" type="text/javascript"></script>
<script src="nvd3/js/fisheye.js" type="text/javascript"></script>
<link href="leaflet/external/leaflet.css" rel="stylesheet"/>
<link href="leaflet/external/leaflet-rCharts.css" rel="stylesheet"/>
<link href="leaflet/external/legend.css" rel="stylesheet"/>
<script src="leaflet/external/leaflet.js" type="text/javascript"></script>
<script src="leaflet/external/leaflet-providers.js" type="text/javascript"></script>
<script src="leaflet/external/Control.FullScreen.js" type="text/javascript"></script>

当加载 nvd3 库时,我猜它是在搞乱传单。
因此,我想知道是否有人可以快速解决此问题?

下面是我的 UI.R 文件 mainPanel 块的摘录
 # nvd3 part part

mainPanel(                                                                                       
tabsetPanel(
tabPanel("All trips", tableOutput("view"), tags$head(tags$style("#view th {color:slategray; background-color: #F2F2F2; text-align:left}", media="screen", type="text/css")),

conditionalPanel(
    condition = "input.comparison == true",
    showOutput('comp1', 'nvd3'),
    br(),
    br(),
    br(),
    br(),
    showOutput('comp2', 'nvd3'),
    br(),
    br(),
    br(),
    br()
      )
    ),

 # leaflet part

tabPanel("Selected trip",
    tabsetPanel(
        tabPanel("map", tags$style('.leaflet {height: 400px;}'), showOutput('myChart', 'leaflet'),
        br(),
        h2("Detailed information", style = "color:slategray; border-bottom:2px solid slategray; padding-bottom: 0.1in"), htmlOutput('details')
  ),


 #...

服务端,我用下面的代码来自定义leaflet
# Plot
dat_list <- toJSONArray2(dat, json = F)

L1 <- Leaflet$new()
mid <- round(nrow(dat),0)/2
L1$setView(c(dat$lat[mid], dat$lng[mid]), 13)

L1$geoJson(toGeoJSON(dat_list, lat = 'lat', lon = 'lng'),
           onEachFeature = '#! function(feature, layer){
           layer.bindPopup(feature.properties.label)
} !#',
           pointToLayer =  "#! function(feature, latlng){
           return L.circleMarker(latlng, {
           radius: 4,
           fillColor: feature.properties.Color || 'red',    
           color: '#000',
           weight: 1,
           fillOpacity: 0.8
           })
} !#"         
           )
L1

}

对于 nvd3 图,如下所示
p <- nPlot(AC ~ Time, group = "id", data = t, type = "lineWithFocusChart")
p$xAxis( tickFormat="#!function(d) {return d3.time.format('%X')(new Date(d));}!#" )
p$x2Axis( tickFormat="#!function(d) {return d3.time.format('%X')(new Date(d));}!#" )

非常感谢!

最佳答案

对我来说,我只需要评论 nv.d3.css 文件中的宽度和高度。

svg {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  display: block;
  /*width:100%;
  height:100%;*/
}

关于rCharts - Shiny 中的传单和 nvd3 之间的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23151171/

相关文章:

javascript - 传单.js : Pass feature property to class constructor

javascript - 传单缩放和平移

unclass(x) : cannot unclass an environment using dplyr filter function 中的 R Shiny 错误

r - 使用相对于另一个元素的动态位置/位置向 ggplot2 图中添加注释

javascript - 我正在尝试通过他们的教程设置 Leaflet map ,但有些东西不起作用,任何人都可以看一看并找出原因吗?

r - 获取与 7 天前日期 'Around' 相关的分数

r - 带有额外行的帮助文本 (R Shiny)

javascript - Shiny未检测到shiny :inputchanged event

r - 使用 R 和 ggplot2 的箱线图图例键的透明度

r - 在排列格罗布之后拆分或删除图形