-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
adding a jinja2 example to the interactive HTML export #4472
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
Jinja2 is a standard, safe, and powerful way to insert content into HTML in Python. I add an example to the documentation
Thank you for this PR @rl-utility-man . We'll look it over and get back to you promptly. |
@rl-utility-man this looks great! I'd like @LiamConnors to review as well, but there are two changes I'd like to see. First, you're using You can insert Plotly output and text related to your data into HTML templates using Jinja2. First create an HTML template file containing a variable like
Then use the following Python to replace
|
Glad to help! Thanks for the good suggestions @alexcjohnson! I just committed a new version than implements them. I welcome further feedback and input from you, @LiamConnors and the Plotly community. |
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.
Thanks @rl-utility-man.
Really nice example! I was able to get it running by following the steps. I just added a few suggestions to the copy for clarity
Co-authored-by: Liam Connors <[email protected]>
@LiamConnors Your edit looks great. Many thanks! I think this is all in a good place, so defer to you and your colleagues about whether we're ready to accept the pull request. |
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.
💃 Looks good to me.
Thanks!
I often need to write one program that inserts Plotly graphics and customized text into an HTML file. Jinja2 is an obvious way to do so. Here I add an example to the documentation.
If your PR modifies code of the
plotly
package, we have a different checklistbelow :-).
Documentation PR
I've seen the
doc/README.md
fileThis change runs in the current version of Plotly on PyPI and targets the
doc-prod
branch OR it targets themaster
branchIf this PR modifies the first example in a page or adds a new one, it is a
px
example if at all possibleEvery new/modified example has a descriptive title and motivating sentence or paragraph
Every new/modified example is independently runnable
Every new/modified example is optimized for short line count and focuses on the Plotly/visualization-related aspects of the example rather than the computation required to produce the data being visualized
Meaningful/relatable datasets are used for all new examples instead of randomly-generated data where possible
[Not applicable] The random seed is set if using randomly-generated data in new/modified examples
New/modified remote datasets are loaded from https://plotly.github.io/datasets and added to https://github.com/plotly/datasets
I welcome a conversation about how to deal with disk files. It's hard to create a realistic example without a read/write file system -- so I left place holders for paths.
Large computations are avoided in the new/modified examples in favour of loading remote datasets that represent the output of such computations
Imports are
plotly.graph_objects as go
/plotly.express as px
/plotly.io as pio
[Not applicable] Data frames are always called
df
fig = <something>
call is high up in each new/modified example (eitherpx.<something>
ormake_subplots
orgo.Figure
)[ Not applicable] Liberal use is made of
fig.add_*
andfig.update_*
rather thango.Figure(data=..., layout=...)
in every new/modified example[ Not applicable ] Specific adders and updaters like
fig.add_shape
andfig.update_xaxes
are used instead of bigfig.update_layout
calls in every new/modified examplefig.show()
is at the end of each new/modified exampleI did not see value to doing so. If this is relevant, please add it.
plotly.plot()
andplotly.iplot()
are not used in any new/modified exampleCode PR
plotly.graph_objects
, my modifications concern thecodegen
files and not generated files.modified existing tests.
new tutorial notebook (please see the doc checklist as well).
-->