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

Try exporting Sankey Diagram for production flow #62

Open
ScottJDaley opened this issue Mar 23, 2020 · 8 comments
Open

Try exporting Sankey Diagram for production flow #62

ScottJDaley opened this issue Mar 23, 2020 · 8 comments
Labels
feature New feature or request

Comments

@ScottJDaley
Copy link
Owner

Not sure if this works with the loops in oil (e.g. pacakged fuel -> empty canister -> packaged water -> ...).

Screen Shot 2020-03-23 at 11 40 27 AM

@ScottJDaley
Copy link
Owner Author

This looks very promising, it even supports interactivity:

https://plot.ly/python/sankey-diagram/

newplot

@ScottJDaley
Copy link
Owner Author

Might be hard to take advantage of the interactivity without using a lot of network (> 3MB per request).

The only thing that might work is the notebook_connected or iframe_connected render options described on this page: https://plot.ly/python/renderers/. These will not include the plotly js library in each output. Both of these are designed to be used with jupyter notebooks.

While I could attach the .ipynb file to the discord message, this requires the user to know how to view it. But I'm wondering if it is possible to ignore the .ipynb file and instead return an html file that references the js code hosted somewhere else.

Also look into this:

fig.write_html("path/to/file.html")

@ScottJDaley
Copy link
Owner Author

import plotly
help(plotly.io.write_html)
write_html(fig, file, config=None, auto_play=True, include_plotlyjs=True, include_mathjax=False, post_script=None, full_html=True, animation_opts=None, validate=True, default_width='100%', default_height='100%', auto_open=False)
    Write a figure to an HTML file representation
    
    Parameters
    ----------
    fig:
        Figure object or dict representing a figure
    file: str or writeable
        A string representing a local file path or a writeable object
        (e.g. an open file descriptor)
    config: dict or None (default None)
        Plotly.js figure config options
    auto_play: bool (default=True)
        Whether to automatically start the animation sequence on page load
        if the figure contains frames. Has no effect if the figure does not
        contain frames.
    include_plotlyjs: bool or string (default True)
        Specifies how the plotly.js library is included/loaded in the output
        div string.
    
        If True, a script tag containing the plotly.js source code (~3MB)
        is included in the output.  HTML files generated with this option are
        fully self-contained and can be used offline.
    
        If 'cdn', a script tag that references the plotly.js CDN is included
        in the output. HTML files generated with this option are about 3MB
        smaller than those generated with include_plotlyjs=True, but they
        require an active internet connection in order to load the plotly.js
        library.
    
        If 'directory', a script tag is included that references an external
        plotly.min.js bundle that is assumed to reside in the same
        directory as the HTML file. If `file` is a string to a local file path
        and `full_html` is True then
    
        If 'directory', a script tag is included that references an external
        plotly.min.js bundle that is assumed to reside in the same
        directory as the HTML file.  If `file` is a string to a local file
        path and `full_html` is True, then the plotly.min.js bundle is copied
        into the directory of the resulting HTML file. If a file named
        plotly.min.js already exists in the output directory then this file
        is left unmodified and no copy is performed. HTML files generated
        with this option can be used offline, but they require a copy of
        the plotly.min.js bundle in the same directory. This option is
        useful when many figures will be saved as HTML files in the same
        directory because the plotly.js source code will be included only
        once per output directory, rather than once per output file.
    
        If 'require', Plotly.js is loaded using require.js.  This option
        assumes that require.js is globally available and that it has been
        globally configured to know how to find Plotly.js as 'plotly'.
        This option is not advised when full_html=True as it will result
        in a non-functional html file.
    
        If a string that ends in '.js', a script tag is included that
        references the specified path. This approach can be used to point
        the resulting HTML file to an alternative CDN or local bundle.
    
        If False, no script tag referencing plotly.js is included. This is
        useful when the resulting div string will be placed inside an HTML
        document that already loads plotly.js.  This option is not advised
        when full_html=True as it will result in a non-functional html file.
    
    include_mathjax: bool or string (default False)
        Specifies how the MathJax.js library is included in the output html
        div string.  MathJax is required in order to display labels
        with LaTeX typesetting.
    
        If False, no script tag referencing MathJax.js will be included in the
        output.
    
        If 'cdn', a script tag that references a MathJax CDN location will be
        included in the output.  HTML div strings generated with this option
        will be able to display LaTeX typesetting as long as internet access
        is available.
    
        If a string that ends in '.js', a script tag is included that
        references the specified path. This approach can be used to point the
        resulting HTML div string to an alternative CDN.
    post_script: str or list or None (default None)
        JavaScript snippet(s) to be included in the resulting div just after
        plot creation.  The string(s) may include '{plot_id}' placeholders
        that will then be replaced by the `id` of the div element that the
        plotly.js figure is associated with.  One application for this script
        is to install custom plotly.js event handlers.
    full_html: bool (default True)
        If True, produce a string containing a complete HTML document
        starting with an <html> tag.  If False, produce a string containing
        a single <div> element.
    animation_opts: dict or None (default None)
        dict of custom animation parameters to be passed to the function
        Plotly.animate in Plotly.js. See
        https://github.com/plotly/plotly.js/blob/master/src/plots/animation_attributes.js
        for available options. Has no effect if the figure does not contain
        frames, or auto_play is False.
    default_width, default_height: number or str (default '100%')
        The default figure width/height to use if the provided figure does not
        specify its own layout.width/layout.height property.  May be
        specified in pixels as an integer (e.g. 500), or as a css width style
        string (e.g. '500px', '100%').
    validate: bool (default True)
        True if the figure should be validated before being converted to
        JSON, False otherwise.
    auto_open: bool (default True
        If True, open the saved file in a web browser after saving.
        This argument only applies if `full_html` is True.
    Returns
    -------
    str
        Representation of figure as an HTML div string

@ScottJDaley
Copy link
Owner Author

This is probably the best option:

fig.write_html("path/to/file.html", include_plotlyjs="cdn")

I still need to check how large these files are.

@ScottJDaley
Copy link
Owner Author

Another option for js sankey diagrams

https://ricklupton.github.io/d3-sankey-diagram/

@ScottJDaley
Copy link
Owner Author

@ScottJDaley
Copy link
Owner Author

I think interactivity can be added to the above d3 based libraries by adding some JavaScript like in these examples: https://www.d3-graph-gallery.com/sankey

@ScottJDaley
Copy link
Owner Author

This post has a guide on adding interactivity and side discussion of images on the nodes in the comments.

http://www.d3noob.org/2014/01/tree-diagrams-in-d3js_11.html?showComment=1399064002918&m=1#c2343298308942321430

@ScottJDaley ScottJDaley added the feature New feature or request label Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant