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

[REF-2921] Layout property not pushed through on rx.plotly #3233

Open
sebastianjanisch opened this issue May 5, 2024 · 2 comments
Open

[REF-2921] Layout property not pushed through on rx.plotly #3233

sebastianjanisch opened this issue May 5, 2024 · 2 comments
Labels
bug Something isn't working linear Created by Linear-GitHub Sync
Milestone

Comments

@sebastianjanisch
Copy link

sebastianjanisch commented May 5, 2024

Describe the bug
A plotly figure has a data and layout property. It seems that currently only the layout data property is handled.

To Reproduce
Steps to reproduce the behavior:

  • Code/Link to Repo:

Rebuilding any example (https://plotly.com/python/line-and-scatter/) that contains layout specifications will not yield the desired result.

Expected behavior
A clear and concise description of what you expected to happen.

Layout descriptions in a plotly figure are accounted for when rendering rx.plotly

Screenshots
If applicable, add screenshots to help explain your problem.

Specifics (please complete the following information):

  • Python Version: 3.11
  • Reflex Version: 0.4.9
  • OS: Sonoma 14.4.1 (23E224)
  • Browser (Optional): chrome

Additional context
Add any other context about the problem here.

REF-2921

@sebastianjanisch
Copy link
Author

There is a rather ugly hack for the time being.
The layout object cannot be serialized right now, but the underlying structure is a plain dict. turning this into a string, then re-evaluating it back to the actual dict and saving it in the state, then passing that through in the plotly component works for now. (I could not find a to_dict or anything. resembling on the plotly layout class).

class MyState(rx.State):
  figure: go.Figure = go.Figure()
  layout: dict[str, Any] = {}

  def on_load(self):
    self.figure = ...
    # some fancy layout properties added to the figure

    self.layout = eval(str(self.figure.layout)[len("Layout(") : -1])


def page() -> rx.Component:
  return rx.plotly(data=MyState.figure, layout=MyState.layout)

@sebastianjanisch
Copy link
Author

Turns out the figure itself has a to_dict function, so we can use self.layout = self.figure.to_dict()["layout'] as a workaround.

@Lendemor Lendemor added the bug Something isn't working label May 7, 2024
@picklelo picklelo added the linear Created by Linear-GitHub Sync label May 23, 2024
@picklelo picklelo changed the title Layout property not pushed through on rx.plotly [REF-2921] Layout property not pushed through on rx.plotly May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working linear Created by Linear-GitHub Sync
Projects
None yet
Development

No branches or pull requests

3 participants