• <i id='NsWp0'><tr id='NsWp0'><dt id='NsWp0'><q id='NsWp0'><span id='NsWp0'><b id='NsWp0'><form id='NsWp0'><ins id='NsWp0'></ins><ul id='NsWp0'></ul><sub id='NsWp0'></sub></form><legend id='NsWp0'></legend><bdo id='NsWp0'><pre id='NsWp0'><center id='NsWp0'></center></pre></bdo></b><th id='NsWp0'></th></span></q></dt></tr></i><div id='NsWp0'><tfoot id='NsWp0'></tfoot><dl id='NsWp0'><fieldset id='NsWp0'></fieldset></dl></div>

    <legend id='NsWp0'><style id='NsWp0'><dir id='NsWp0'><q id='NsWp0'></q></dir></style></legend>
      <bdo id='NsWp0'></bdo><ul id='NsWp0'></ul>
  • <tfoot id='NsWp0'></tfoot>

        <small id='NsWp0'></small><noframes id='NsWp0'>

      1. 情节上任何地方的情节点击事件

        plotly click events from anywhere on the plot(情节上任何地方的情节点击事件)
      2. <tfoot id='lV4Od'></tfoot>

          1. <legend id='lV4Od'><style id='lV4Od'><dir id='lV4Od'><q id='lV4Od'></q></dir></style></legend>

                <bdo id='lV4Od'></bdo><ul id='lV4Od'></ul>
                  <tbody id='lV4Od'></tbody>
                  <i id='lV4Od'><tr id='lV4Od'><dt id='lV4Od'><q id='lV4Od'><span id='lV4Od'><b id='lV4Od'><form id='lV4Od'><ins id='lV4Od'></ins><ul id='lV4Od'></ul><sub id='lV4Od'></sub></form><legend id='lV4Od'></legend><bdo id='lV4Od'><pre id='lV4Od'><center id='lV4Od'></center></pre></bdo></b><th id='lV4Od'></th></span></q></dt></tr></i><div id='lV4Od'><tfoot id='lV4Od'></tfoot><dl id='lV4Od'><fieldset id='lV4Od'></fieldset></dl></div>
                • <small id='lV4Od'></small><noframes id='lV4Od'>

                • 本文介绍了情节上任何地方的情节点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 r-plotly 的新手,并试图弄清楚如何处理不在数据上的点击.似乎使用 event_data("plotly_click") 我得到了数据点上的事件,但到目前为止还没有弄清楚如何为不接近数据的点击执行此操作,但是就在情节的白色部分.

                  来自绘图的闪亮点击事件可以做到这一点,我只得到点击的 x 和 y.我想要类似的,但对于情节.

                  我可以将点击事件指定为来自绘图上的任何位置,而不仅仅是在数据上吗?

                  令人惊讶的是,这在情节中还不存在.查看此功能请求


                  这是使用 plotlyProxy 而不是重新渲染的相同方法 - 偏移量更糟:

                  图书馆(情节)图书馆(闪亮)图书馆(htmlwidgets)ui <-流体页面(plotlyOutput("myPlot"),逐字文本输出(点击"))服务器 <- 功能(输入,输出,会话){js <-"函数(el,x,输入名称){var id = el.getAttribute('id');var gd = document.getElementById(id);var d3 = Plotly.d3;Plotly.plot(id).then(attach);函数附加(){var xaxis = gd._fullLayout.xaxis;var yaxis = gd._fullLayout.yaxis;var l = gd._fullLayout.margin.l;var t = gd._fullLayout.margin.t;var 坐标 = [null, null]gd.addEventListener('click', function(evt) {var 坐标 = [xaxis.p2c(evt.x - l), yaxis.p2c(evt.y - t)];Shiny.setInputValue(inputName, 坐标);});};}"clickposition_history <-reactiveVal(data.frame(x = NA, y = NA))观察事件(输入$点击位置,{clickposition_history(rbind(clickposition_history(), input$clickposition))})输出$myPlot <- renderPlotly({plot_ly(data.frame(x = NA, y = NA), x = ~x, y = ~y, type = "scatter", mode = "markers") %>%onRender(js, data = "点击位置")})myPlotProxy <- plotlyProxy(myPlot", session)观察({plotlyProxyInvoke(myPlotProxy, "restyle", list(x = list(clickposition_history()$x), y = list(clickposition_history()$y)))})输出$click <- renderPrint({clickposition_history()})}闪亮的应用程序(用户界面,服务器)

                  相关的 GitHub 问题 和 PR.

                  I am new to r-plotly and trying to figure out how to handle clicks which are not on the data. It seems that using event_data("plotly_click") I get events that are on points from the data, but so far have not figured out how to do this for clicks which are not close to the data, but just on the white part of the plot.

                  Shiny click events from plots can do this and I just get the x and y of the click. I want similar, but for plotly plots.

                  Can I specify click events to be from anywhere on the plotly plot, not just on the data?

                  EDIT: Surprisingly this does not exist yet in plotly. See this feature request

                  https://github.com/plotly/plotly.js/issues/2696

                  https://github.com/ropensci/plotly/issues/1194

                  So until this feature is added, I guess my question is what options are there to do this? Seems like such a basic feature, that I hope someone with more knowledge of JavaScript/Shiny/Plotly has hacked into.

                  解决方案

                  Please check the following workaround based on this codepen I found via this question.

                  However, there is a small horizontal offset I couldn't get rid of so far - maybe someone knows how to fix it?

                  library(plotly)
                  library(shiny)
                  library(htmlwidgets)
                  
                  ui <- fluidPage(
                    plotlyOutput("graph"),
                    verbatimTextOutput("click")
                  )
                  
                  server <- function(input, output, session) {
                    
                    js <- "
                      function(el, x, inputName){
                        var id = el.getAttribute('id');
                        var gd = document.getElementById(id);
                        var d3 = Plotly.d3;
                        Plotly.plot(id).then(attach);
                          function attach() {
                            var xaxis = gd._fullLayout.xaxis;
                            var yaxis = gd._fullLayout.yaxis;
                            var l = gd._fullLayout.margin.l;
                            var t = gd._fullLayout.margin.t;
                            var coordinates = [null, null]
                      
                            gd.addEventListener('click', function(evt) {
                              var coordinates = [xaxis.p2c(evt.x - l), yaxis.p2c(evt.y - t)];
                              Shiny.setInputValue(inputName, coordinates);
                            });
                          };
                    }
                    "
                    clickposition_history <- reactiveVal(data.frame(x = 1:10, y = 1:10))
                    
                    observeEvent(input$clickposition, {
                      clickposition_history(rbind(clickposition_history(), input$clickposition))
                    })
                    
                    output$graph <- renderPlotly({
                        plot_ly(clickposition_history(), x = ~x, y = ~y, type = "scatter", mode = "markers") %>%
                        onRender(js, data = "clickposition")
                    })
                    
                    output$click <- renderPrint({
                      input$clickposition
                    })
                  }
                  
                  shinyApp(ui, server)
                  


                  Edit:

                  Here is the same approach using plotlyProxy instead of re-rendering - the offset is even worse:

                  library(plotly)
                  library(shiny)
                  library(htmlwidgets)
                  
                  ui <- fluidPage(
                    plotlyOutput("myPlot"),
                    verbatimTextOutput("click")
                  )
                  
                  server <- function(input, output, session) {
                    
                    js <- "
                      function(el, x, inputName){
                        var id = el.getAttribute('id');
                        var gd = document.getElementById(id);
                        var d3 = Plotly.d3;
                        Plotly.plot(id).then(attach);
                          function attach() {
                            var xaxis = gd._fullLayout.xaxis;
                            var yaxis = gd._fullLayout.yaxis;
                            var l = gd._fullLayout.margin.l;
                            var t = gd._fullLayout.margin.t;
                            var coordinates = [null, null]
                  
                            gd.addEventListener('click', function(evt) {
                              var coordinates = [xaxis.p2c(evt.x - l), yaxis.p2c(evt.y - t)];
                              Shiny.setInputValue(inputName, coordinates);
                            });
                          };
                    }
                    "
                    clickposition_history <- reactiveVal(data.frame(x = NA, y = NA))
                    
                    observeEvent(input$clickposition, {
                      clickposition_history(rbind(clickposition_history(), input$clickposition))
                    })
                    
                    output$myPlot <- renderPlotly({
                      plot_ly(data.frame(x = NA, y = NA), x = ~x, y = ~y, type = "scatter", mode = "markers") %>%
                        onRender(js, data = "clickposition")
                    })
                    
                    myPlotProxy <- plotlyProxy("myPlot", session)
                    
                    observe({
                      plotlyProxyInvoke(myPlotProxy, "restyle", list(x = list(clickposition_history()$x), y = list(clickposition_history()$y)))
                    })
                    
                    output$click <- renderPrint({
                      clickposition_history()
                    })
                  }
                  
                  shinyApp(ui, server)
                  

                  Related GitHub issue and PR.

                  这篇关于情节上任何地方的情节点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  业务场景:使用update语句去更新数据库字段。 原因:update接收值不正确。原来代码: $query = "UPDATE student SET date = now() WHERE id = $id";$result = $mysqli-query($query2) or die($mysqli-error); // 问题出现了在这句 $data = $result-fetch_ass
                  在layui树状组件tree中,勾选问题可以通过以下方法解决: 通过tree的oncheck事件来监听勾选操作,然后根据勾选状态进行相应的处理。例如: tree.on('check', function(obj) { // 获取勾选状态 var isChecked = obj.checked; // 获取当前节点数据 var data =
                  经常用到layui的朋友都知道,layui tree默认是不能自定义图标的,那么我们要自定义的话要怎么操作呢? 首先用编辑器软件(修改时候用编辑器记得编码),打开layui.js。搜索: i class="layui-icon layui-icon-file" 改为如下代码: i class="'+ (i.icon || "l
                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转

                    <tbody id='ewYTw'></tbody>
                      <legend id='ewYTw'><style id='ewYTw'><dir id='ewYTw'><q id='ewYTw'></q></dir></style></legend>

                        • <bdo id='ewYTw'></bdo><ul id='ewYTw'></ul>

                          <small id='ewYTw'></small><noframes id='ewYTw'>

                            <tfoot id='ewYTw'></tfoot>
                            <i id='ewYTw'><tr id='ewYTw'><dt id='ewYTw'><q id='ewYTw'><span id='ewYTw'><b id='ewYTw'><form id='ewYTw'><ins id='ewYTw'></ins><ul id='ewYTw'></ul><sub id='ewYTw'></sub></form><legend id='ewYTw'></legend><bdo id='ewYTw'><pre id='ewYTw'><center id='ewYTw'></center></pre></bdo></b><th id='ewYTw'></th></span></q></dt></tr></i><div id='ewYTw'><tfoot id='ewYTw'></tfoot><dl id='ewYTw'><fieldset id='ewYTw'></fieldset></dl></div>