Jupyter4Science / scipy23-jupyter-web-app-tutorial

A 4-hour tutorial entitled "How the Little Jupyter Notebook Became a Web App: Managing Increasing Complexity with nbdev" presented at SciPy 2023 in Austin, TX.
https://cfp.scipy.org/2023/talk/NFWZXD/
Apache License 2.0
6 stars 4 forks source link

decide about the location of views and models #10

Closed nicole-brewer closed 1 year ago

nicole-brewer commented 1 year ago

In the Superpower project, I split up a particular StatsModel by model and view. For example, I chose to split ANOVA into superpower.model.ANOVAModel and superpower.view.ANOVAView. I didn't love that arrangement because I couldn't edit models and views in the same notebook.

So for this project, I'm going to start by putting the Model and View in the same module, for example jupyter-web-app-template.data.DataModel and jupyter-web-app-template.data.DataView. That way the first view can be developed in the same notebook as the model. Not sure what that will look like as I add more views. Can I have a default export that references another module? Or would I have to offload it to jupyter-web-app-template.data.views.DataView? And then the original view (jupyter-web-app-template.data.DataView) would be in a different place than all the other views which would be confusing.

Maybe the answer is to create a jupyter-web-app-template.data.views before creating the view in jupyter-web-app-template.data.ipynb. This works as long as the models are "one-to-many" views. If there is a view that accommodates more than one kind of model, we probably have to resort the the superpower setup mentioned earlier. But I don't even think that superpower was "many-to-many" so that probably isn't an issue.

nicole-brewer commented 1 year ago

I discovered that there is actually a lot of flexibility in the naming because it doesn't rely on directories being correct. That way, I can organize the notebooks any way I want and sort them out in the library totally differently. so I will have jupyter_web_app_template.data.model and jupyter_web_app_template.data.views.plot_view.

... well wait. Can I just do jupyter_web_app_template.data.views import PlotView. That is where there are multiple notebooks contributing to a single "views" module?

nicole-brewer commented 1 year ago

I'm not getting an error, but the code from data.ipynb labeled for export to data.views is not showing up.

nicole-brewer commented 1 year ago

This makes me think I'm supposed to be able to export outside the default (as the the word "default") but I don't see any evidence of this in the documentation. My next thought is that the dependency order matters. That is, the notebook that has the (non-default) export to data.views, may be converted first and then overwritten by the notebook with the default export to data.views. Maybe if the dependency was listed this wouldn't happen?

nicole-brewer commented 1 year ago

I didn't get around to trying that because I'm pretty sure it wouldn't do any good. I tried to two notebooks with the same default export to see if they would combine but they don't. So I think notebooks are one-to-one with modules. Changing this would be a great feature to nbdev I think.

nicole-brewer commented 1 year ago

So here's what I've come up with. The module jupyter_web_app_template.data.view.table will live in nbs/data/view.table.ipynb. That way there is some directory structure but not too many levels without things in them. But honestly, for the tutorial, it may make more sense to be in a flat directory using filenames with dot notation. This way I can number all the ones to be accessed and there isn't confusion hopping in and out of directories.

So for the tutorial I will have a flat structure but if I turn it into a template it will have some directories in there for better organization.

nicole-brewer commented 1 year ago

See above comment