niloch / iplotter

JavaScript charting in ipython/jupyter notebooks -
http://niloch.github.io/iplotter/
MIT License
85 stars 10 forks source link

Pandas Integration #10

Closed WaylonWalker closed 2 years ago

WaylonWalker commented 7 years ago

First of all this is a great library that implements really well into the jupyter notebook. I could see this working really well with Flask as well. I generally use pandas for my analysis. Would you be open to adding pandas integration into iplotter or accepting a PR with pandas integration. I have roughed out the idea in my fork https://github.com/WaylonWalker/iplotter. I would like to include most of the pandas dataframe.plot() methods, as well as new features from the JavaScript Libraries.

niloch commented 7 years ago

Thanks for the feedback! If you want to do something similar with Flask, I think it makes the most sense to have one route to return the HTML template, and then have javascript call a separate endpoint to get the data and then render normally in the browser. But that's up to you. You could, of course, have the template return the page with the data embedded in the javascript as in the save method which creates a full html file.

As far as the pandas integration goes, I think it's an interesting idea. The examples you created for c3.js are nice. I think, instead of altering the render function it would be better to add a dataframe_plot method that wraps a call to the existing plot function. Essentially, I think dataframe_plot method should have the same function signature as pandas.DataFrame.plot and internally it will handle all the manipulation of the data to get it compliant with expected javascript framework.

I'm happy to consider a PR that can be extrapolated to all the different javascript libraries.

Thanks again.

WaylonWalker commented 7 years ago

I haven't had a use case for Flask yet, but have a project coming using Flask that I will test it out with. I think that having the separate methods for .plot and .render will make it easy to move from an ad hoc notebook to a flask api.

I'll keep working on it as time allows. I would probably work each js library one at a time. Rather than adding dataframe_plot I would rather keep the plot method and have plot decide if a DataFrame Series or dict type was passed. Would you oppose having it tied to plot?

niloch commented 7 years ago

Another cool project for interactive dashboards is Dash from plotly. It seems to be a good Python analog to Shiny in R.

I think incrementally adding pandas support to each js library is totally fine. We'd just specify an abstract method in the base class to be implemented.

However, since pandas is not currently a dependency of this project, and the user is responsible for properly formatting data into the schema for each js library, I am very reluctant to add internal logic to the plot method to allow it to behave differently depending on the data type.

Essentially, plot assumes the data parameter to be properly defined Python dictionaries and lists that can be converted to JSON. I don't think it would be a good practice to introduce ambiguity into the data type, just to allow support for pandas.