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

allows plotly plots to be optionally placed in another div #178

Closed
wants to merge 1 commit into from

Conversation

hottwaj
Copy link

@hottwaj hottwaj commented Feb 12, 2019

allows plotly plots to be optionally placed in another div by specifying the div id as "div_id" in the MIME json package

If present, the target div id is passed to plotly which takes care of rendering the chart in the given div

implements #173

Perhaps this is not of interest to anyone else and I'm happy to just keep these changes in my own fork, so feel free to reject this PR.

In case its of interest the reason I quite like using this is to create more complex chart layouts by first setting out a set of divs or a table to contain the charts, and then rendering all the charts

e.g.

class PlotlyMIMEBundle(object):
    def __init__(self, data=[], layout={}, div_id=None):
        bundle = {}
        bundle['application/vnd.plotly.v1+json'] = { 
            'data': data, 
            'layout': layout, 
            'div_id': div_id
        }
        self.bundle = bundle
    
    def _repr_mimebundle_(self, *args, **kwargs):
        return self.bundle

display(HTML("<div id="chart1"></div><div id="chart2"></div>"))
display(PlotlyMIMEBundle(data = [{"x": [1, 2, 3], "y": [3, 1, 6]}], div_id = "chart1"))
display(PlotlyMIMEBundle(data = [{"x": [5, 4, 3], "y": [3, 1, 6]}], div_id = "chart2"))

Thanks!

@ian-r-rose
Copy link
Member

Sorry for the very slow response @hottwaj! The plotly extension in this repo has now been deprecated in favor of the official jupyterlab-plotly extension developed by Plotly. Does your fix here also apply to that extension? If so, would you mind opening the same PR over there?

@hottwaj
Copy link
Author

hottwaj commented Nov 21, 2019 via email

@fcollonval
Copy link
Member

Closing as plotly is maintaining officially its renderer: https://github.com/plotly/plotly.py

@fcollonval fcollonval closed this Jan 14, 2022
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