Skip to content

Instantly share code, notes, and snippets.

@flying-sheep
Last active November 6, 2018 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flying-sheep/2ded901bf6a914164ece83792a82f061 to your computer and use it in GitHub Desktop.
Save flying-sheep/2ded901bf6a914164ece83792a82f061 to your computer and use it in GitHub Desktop.
Plotly python offline click events in notebook
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