Plotly python offline - visit url on click?

空扰寡人 提交于 2019-12-07 08:01:06

问题


Is it possible to configure a plotly plot so that the user is taken to a specific url when they click on a certain data point?

My intended usage is for bar charts: I'd like to be able to click on a bar and then be taken to a url, each bar being configured with a different url.

I'm using plotly python offline to create a <div> which I'm embedding in a website.

Is this possible with the postMessage API on plotly python offline mode?


回答1:


Here I have created an example for you to edit here - right now it has the bars defined Bar1 Bar2 Bar3 Bar4 which indexes a URL for each in the JavaScript code (edit to your liking). In order to use the PostMessage API the barchart you made has to be embedded in an iframe (see how to do it in the codepen link HTML section) and the JavaScript has to be included (on the right pane in the codepen link).

Full running example: http://codepen.io/mslezak/pen/ZWxMBP

Plotly chart embedded: https://plot.ly/~mslezak/11/y-vs-x/



来源:https://stackoverflow.com/questions/36401538/plotly-python-offline-visit-url-on-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!