【问题标题】:Weird behaviour leaflet and Shiny奇怪的行为传单和闪亮
【发布时间】:2015-08-25 00:53:05
【问题描述】:

我有一个使用传单库的闪亮应用程序。 我现在需要使用get.Bounds() 函数来获取一些坐标。很简单(js file):

var myBounds = map.getBounds();
console.log(myBounds);

然后我需要将坐标发送给闪亮进行进一步处理(也在我的js file

Shiny.onInputChange("bounds", myBounds);

要查看这是否有效,它在server.R 中这样做了:

observe({
  print(input$bounds)
})

但是,当我在 R 控制台中运行应用程序时,会出现 NULL。通过我的.js file 中的console.log,坐标会打印在Firefox 控制台中。

但是,它时不时地起作用。当我运行 Shiny App 十次时,它有时会运行 3 次,有时会运行 4 次,有时甚至不会运行。我得到坐标并将它们打印到 R 控制台中。

我也尝试过reactive,但这并没有成功。这里的行为相同。

#get extensions of map
  myBoundsR <- reactive({
  input$bounds
 })
#print extensions
observe(print(myBoundsR()))

这是为什么?!为什么这种行为不合时宜?!为什么Shiny.onInputChange("bounds", myBounds);这行不把坐标发给server.R

【问题讨论】:

    标签: javascript r shiny leaflet


    【解决方案1】:

    你可能想这样改变它:

     map.on('moveend', function(e) {
     var myBounds = map.getBounds();
     Shiny.onInputChange("bounds", myBounds);
     console.log(myBounds);
     });
    

    可能是“开始窗口”没有发送窗口扩展的问题?!这只是一个猜测。我找不到任何东西。由于js 只经过一次,从上到下,代码只执行一次。 以这种方式编写,它应该在您平移/缩放时工作?!

    如果这对你有帮助,请告诉我!

    【讨论】:

    • 现在效果更好了。时不时我会得到一个NULL 值。但是,这种情况很少发生。
    猜你喜欢
    • 1970-01-01
    • 2021-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-19
    • 2018-01-15
    • 2015-03-25
    • 2019-04-11
    相关资源
    最近更新 更多