简体   繁体   English

回调函数在python代码中离线

[英]Callback function plotly offline in python code

I read about click events of the python API.我阅读了 python API 的点击事件。 There is something in javascript here https://plot.ly/javascript/lasso-selection/ but I'd like to do it in pure python (if possible).这里的 javascript 中有一些东西https://plot.ly/javascript/lasso-selection/但我想用纯 python 来做(如果可能的话)。

I will try to be as clear as possible.我会尽量说清楚。

I'm developing a plugin in QGIS ( http://qgis.org/en/site/ ) that will take the attributes of geographic data and use them as input for some plotly charts.我正在 QGIS ( http://qgis.org/en/site/ ) 中开发一个插件,它将采用地理数据的属性并将它们用作一些绘图图表的输入。

What I need is to know if it is possible to have a "back signal" of the points (or lines or whatever) selected with the lassoo selection button.我需要知道是否可以使用套索选择按钮选择点(或线或其他任何东西)的“后退信号”。

I'm trying to create a dinamic response between QGIS map canvas and the html file produced by plotly.我正在尝试在 QGIS 地图画布和 plotly 生成的 html 文件之间创建动态响应。 So that the user can select points on the plot and they will be selected also on the map canvas (and viceversa).这样用户就可以在绘图上选择点,并且它们也将在地图画布上被选择(反之亦然)。

One idea is to use the lassoo selection and get some information (point unique ID for example) and re-inject it so that QGIS will display the selected points on the map canvas.一种想法是使用套索选择并获取一些信息(例如点唯一 ID)并重新注入它,以便 QGIS 将在地图画布上显示选定的点。

Is there any chance to obtain a kind of signal of the plots selection and use it?有没有机会获得一种地块选择的信号并使用它?

Thanks to all谢谢大家

I'd love this feature too, but I'm afraid we'll have to wait for the plotly.dash "re-thinking" for it to be possible in python.我也很喜欢这个功能,但恐怕我们将不得不等待plotly.dash “重新思考”它在 python 中成为可能。

But it might be possible to mash together this flask chat app with the plotly example in your question .但是有可能将这个烧瓶聊天应用程序您问题中情节示例混搭在一起。

We'd replace the console.log call in the callback from the plotly lasso example with a socket.emit from the websockets flask app:我们将使用 websockets socket.emit应用程序中的 socket.emit 替换 plotly lasso 示例中回调中的console.log调用:

graphDiv.on('plotly_selected', function(eventData) {
   console.log(eventData.points)
   socket.emit(eventData.points)
});

And our flask server would serve up an html template with the socket.io javascript for the chat app, but add to the HTML the <DIV> from the offline plotly plot, like this:我们的 Flask 服务器将为聊天应用程序提供带有socket.io javascript 的 html 模板,但将脱机绘图中的<DIV>添加到 HTML 中,如下所示:

fig = graph_objs.Figure(data=[trace1, trace2])
html_div, divid, width, height = plotly.offline.offline._plot_html(
        fig, config=config, validate=False, default_width="100%", default_height=525, global_requirejs=False)
    html = '<HTML>\n<head>\n  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>\n</head>\n<body>' + html_div + '</body></HTML>'

I've left out the flask html/js in the string appending above, but you get the idea.我在上面附加的字符串中遗漏了flask html/js,但你明白了。 If I get something working I'll update.如果我得到一些工作,我会更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM