Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add unsafe_update_figure doc #1058

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jnumainville
Copy link
Collaborator

Adds an unsafe_update_figure doc with some usages that I have been asked for or otherwise seen.

@jnumainville jnumainville marked this pull request as ready for review December 9, 2024 20:52
@jnumainville jnumainville requested a review from dsmmcken December 9, 2024 20:52
> [!WARNING]
> `dx` maps `Table` columns to an index of a trace within `Figure.data` which will break if the trace order changes. Do not remove traces. Add new traces at the end of the list.

`unsafe_update_figure` accepts a function that takes a Plotly `Figure` object as input and optionally returns a modified `Figure` object. If a figure is not returned, it is assumed that the input figure has been modified in place.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should link to full plotly.js docs where they can see figure docs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, linked on the first instance

A Plotly [`Figure`](https://plotly.com/python/figure-structure/) object backs every `dx` chart, and `unsafe_update_figure` allows you to directly modify this object.

> [!WARNING]
> `dx` maps `Table` columns to an index of a trace within `Figure.data` which will break if the trace order changes. Do not remove traces. Add new traces at the end of the list.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would directly state why it is labelled "unsafe" at the start of this warning.

Update figure is marked "unsafe" because some modifications can entirely break your figure, and care must be taken to not ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@bmingles bmingles Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be helpful to explicitly call out the relationship of unsafe_update_figure to the plotly docs. I found it very confusing searching for update_figure in the plotly docs since I wrongfully assumed unsafe_update_figure was a wrapper for something with a similar name. I found the figure reference doc (https://plotly.com/python/reference/) to be a little more helpful in helping me find what I was looking for. It has more direct figure.update_xxx examples throughout.

I left a suggested change above.

Copy link
Contributor

@bmingles bmingles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants