-
Notifications
You must be signed in to change notification settings - Fork 0
🐛 Fix: add code to handle plotly plots generated with R #96
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
Conversation
|
This closes #90 |
|
Hey @enryH, can we still include these changes in the 0.3 release? |
yes, I will review now. |
| plot_code += """ | ||
| fig_plotly = pio.from_json(plot_json) | ||
| # Keep only 'data' and 'layout' sections | ||
| plot_json = {key: plot_json[key] for key in plot_json if key in ['data', 'layout']}\n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually how Alberto also did it for most plots in vuecore. Is there any user formatting specified in the rest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the R plotly plots, there are additional attributes related to shiny and other stuff, but Python raises errors when loading this info, so it only expects to have data and layout
| # Convert JSON to string | ||
| plot_json_str = json.dumps(plot_json)\n | ||
| # Create the plotly plot | ||
| fig_altair = alt.Chart.from_json(plot_json_str).properties(width=900, height=400)\n""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure it does not work when the string in indented? It makes the library a bit hard to read. If it is required for now, try to use textwrap.dedent : https://docs.python.org/3/library/textwrap.html#textwrap.dedent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the problem is that when you write the code into the Python or qmd files, the code is not formatted correctly if indented. I will check dedent.
| "plot": { | ||
| r.PlotType.ALTAIR: ["import altair as alt", "import requests"], | ||
| r.PlotType.PLOTLY: ["import plotly.io as pio", "import requests"], | ||
| r.PlotType.ALTAIR: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this also affect altair?
| # Remove 'frame' section in 'data' | ||
| plot_json['data'] = [{k: v for k, v in entry.items() if k != 'frame'} for entry in plot_json.get('data', [])] | ||
| st.plotly_chart(plot_json, use_container_width=True)\n""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same. maybe dedent as it's better to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, before I was using read_file to read the json for both plotly and altair, but as I updated it to use json, both need it now
No description provided.