Last active
November 6, 2018 13:38
-
-
Save flying-sheep/2ded901bf6a914164ece83792a82f061 to your computer and use it in GitHub Desktop.
Plotly python offline click events in notebook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
title = 'blah' | |
iplot(dict( | |
data=[dict( | |
type='scatter', | |
mode='markers', | |
x=sorted_info.Submission, | |
y=sorted_info.NSamples, | |
text=sorted_info.Series.map(lambda s: s.accession), | |
transforms=[dict( | |
type='groupby', | |
groups=sorted_info.Protocol, | |
)], | |
)], | |
layout=dict( | |
title=title, | |
hovermode='closest', | |
width=800, | |
height=600, | |
xaxis=dict(title='Submission date', dtick='M12'), | |
yaxis=dict(title='# Cells', type='log'), | |
), | |
), validate=False, show_link=False) | |
display(Javascript(rf''' | |
const [cellplot] = Array.from(document.querySelectorAll('.js-plotly-plot')) | |
.filter(n => n.querySelector('text.gtitle').textContent === '{title}') | |
cellplot.on('plotly_click', (data) => {{ | |
if (data.points.length > 1) return | |
const series = data.points[0].text | |
window.open(`https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=${{series}}`,'_blank') | |
}}) | |
''')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment