Skip to content

Instantly share code, notes, and snippets.

@kunalgoyal9
Created May 10, 2023 10:41
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 kunalgoyal9/7b6ad19d11dccec19870e5aac2dfb8a5 to your computer and use it in GitHub Desktop.
Save kunalgoyal9/7b6ad19d11dccec19870e5aac2dfb8a5 to your computer and use it in GitHub Desktop.
import plotly.graph_objects as go
# Create the figure
fig = go.Figure()
# Add the text annotation
annotation = go.layout.Annotation(
x=-0.047,
y=1.025,
xref="paper",
yref="paper",
xanchor="left",
yanchor="top",
bordercolor="black",
borderwidth=1,
borderpad=4,
text="id: {person['id']}<br>"
+ "user_id: {person['user_id']}<br>"
+ "test_id: {person['test_id']}<br>"
+ "exam_id: {person['exam_id']}",
visible=True, # Initially visible
)
# Add the annotation to the figure's layout
fig.update_layout(annotations=[annotation])
# Define the button
button = dict(
label='Hide/Show Text',
method='update',
args=[{'annotations[0].visible': False if annotation.visible else True}],
)
# Add the button to the layout
fig.update_layout(
updatemenus=[go.layout.Updatemenu(
buttons=[button],
direction='down',
pad={'r': 10, 't': 10},
showactive=True,
x=0.1,
xanchor='left',
y=1.1,
yanchor='top'
)]
)
# Show the figure
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment