Code Monkey home page Code Monkey logo

Comments (6)

JanPalasek avatar JanPalasek commented on August 16, 2024 1

Plotly can be used in Jinja Markdown (Markdown with Python variables) this way:

Cell 1:

import plotly.express as px
fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])

Cell 2:

%%jmd
Texts

{{ fig.to_html(include_plotlyjs=False) }}

With plot between them

Alternatively we can use “cdn” instead of False to load from online.
This way ensures interactivity after export using Pretty Jupyter. Also the outputted plot is shown in the JupyterLab as well.

Other environments, such as Jupyter Notebook or Visual Studio Code, have a problem with displaying plotly graphs this way. They just aren't rendering the outputted HTML. Hence on those platforms (vscode, jupyter notebook, NOT jupyterlab) if you combine markdown and Python variables, you won't see the outputted plot in the IDE, just in the exported notebook. To display the plot, this works in all environments: fig.show(renderer="browser") (fig.show(renderer="iframe") can also be considered).

So for Pretty Jupyter the best way is to create html and render that. This works works best in JupyterLab. In other environments, you can still use it. It won't be visible in the IDE, but you can view the plot e.g. with fig.show(renderer="browser").

from pretty-jupyter.

JanPalasek avatar JanPalasek commented on August 16, 2024

Hello,

Thank you, I'm glad you like it. I believe that plotly is already supported.

I'm one hundred percent sure that plotly.offline.plot works. You can create html using this function and then just print it, for example using Jinja Markdown like this: {{ plotly.offline.plot(fig, include_plotlyjs=False, output_type='div') }}.

I'll check out other methods too and add it to the examples. However, generally, it is possible.

from pretty-jupyter.

JanPalasek avatar JanPalasek commented on August 16, 2024

It seems to be a bit deeper issue than I previously suspected. I will add support it for the following:

  • Plotly graph needs to be viewable in Jupyter. Ideally for both Jinja Markdown and normal code cells.
  • Plotly graph needs to be working after export to HTML. It must be available without internet load.

from pretty-jupyter.

fyenne avatar fyenne commented on August 16, 2024

Cool! I will try. Thank you!

from pretty-jupyter.

JanPalasek avatar JanPalasek commented on August 16, 2024

@fyenne I improve the support in a new version 1.2.4. Now dynamic graphs are supported as well as they are in default nbconvert. I tested it for plotly and highchart both (python-highchart package). I added example with plotly to the example here: https://github.com/JanPalasek/pretty-jupyter-examples/tree/main/main-features-demo .

You can use also fig.show() (without any parameter) and it will be shown in any IDE (jupyter, jupyterlab, vs code) and it will be also shown in the exported html by pretty-jupyter.

from pretty-jupyter.

fyenne avatar fyenne commented on August 16, 2024

thank you~

from pretty-jupyter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.