Skip to content

Conversation

@sayalaruano
Copy link
Collaborator

No description provided.

@sayalaruano
Copy link
Collaborator Author

sayalaruano commented Mar 21, 2025

This closes #90

@sayalaruano sayalaruano requested a review from enryH March 21, 2025 08:21
@sayalaruano
Copy link
Collaborator Author

Hey @enryH, can we still include these changes in the 0.3 release?

@enryH
Copy link
Collaborator

enryH commented Mar 21, 2025

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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"""
Copy link
Collaborator

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

Copy link
Collaborator Author

@sayalaruano sayalaruano Mar 21, 2025

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: [
Copy link
Collaborator

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"""
Copy link
Collaborator

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

Copy link
Collaborator Author

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

@enryH
Copy link
Collaborator

enryH commented Mar 21, 2025

This closes #96

this is 96:) you mean this closes #90

@sayalaruano sayalaruano merged commit b4ec570 into main Mar 21, 2025
16 checks passed
@sayalaruano sayalaruano deleted the plotly-r-bug branch March 21, 2025 14:10
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.

3 participants