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

Slight modification of main, styles, and script to automate notebook to HTML #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rlphillips
Copy link

Hello!

I've taken this project and slightly modified the main.html in order to parametrize the name of the html used as template. render.py now takes two parameters: name of the template to use, and name of the output file.

There's a bash script to run with the jupyter notebook you might be using, that deals with the nbconvert and calling render.py. I've tested with a few sample files, and I'm uploading one as a sample.

I've also added a bit of the styles for tables, that seemed to be missing.

Copy link
Owner

@cbernet cbernet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rlphillips and thanks for your interest and your contribution!

I completely understand what you want to do, which is to make these tools usable in general. And that's a very good idea!

But at the same time, for now, the purpose of this repository is to serve as a reference for my blog post. So this repository should stay in sync with the post. For now, it means that the current behaviour should be preserved. I can also change the post later on, when we converge on the solution.

For this reason, I cannot accept the PR as it is, and would like to suggest a few changes.

Also, I think that we should try and get rid of the bash scripts, we can get the functionalities you need with python.

At some point, we could even think of a proper python package. I hadn't done it because I was not expecting this repo to start coming to life :-)

Finally, the docker solution is quite interesting, and I'm a big fan of docker myself. We can go further later on, and provide a docker file that does what we want.

Cheers!

</pre>

{% include 'overfitting.html' %}
{% include FNAME %}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If used out of your scripts, FNAME is undefined. So the current behavior is not preserved. Could you use jinja2 in python instead of sed in a shell script to replace FNAME?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right: Here, I was using FNAME as a placeholder and replacing it in the bash Script: The "template/main.html" file was copied into "template/[name-of-the-notebook].html" file, and replaced FNAME with the name of the html created in the previous step.

@@ -15,8 +16,8 @@
loader = FileSystemLoader('templates'),
)

input_file = 'main.html'
output_file = 'index.html'
input_file = sys.argv[1]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current behaviour is not preserved. Could you please do the following?

  • update the README.md file to give the proper way to run render.py
  • document the new arguments in render.py
  • deal with incorrect numbers of arguments (exit and print help in this case)

@@ -559,3 +559,33 @@ div.output_javascript:empty {
.th {
text-center: left;
}


.dataframe tbody tr {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, I look forward to see the new style.

@@ -0,0 +1,33 @@
#!/usr/bin/bash
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this specific to your workflow? if yes, could you remove this file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, you are right.


#First argument: File name of the notebook to work on: e.g., if the notebook is analysis.ipynb, argument is analysis.

cd notebooks/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea, but I think that it would be better to write this code in python instead of in a shell script.

I think that a good interface could be:

python  render.py  base.html  my_nb_1.ipynb  my_nb_2.ipynb ... 
  • The user could provide any number of notebooks to insert.
  • In my_output.html, we would use jinja2 tags to specify where each notebook should be inserted, based on the name the notebook
  • The script would run jupyter nbconvert (maybe there is a python API, or with os.system or something)
  • Finally, the ouput file would be rendered

One could also think about the options. For example, the name of the output file (index.html by default)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll use this interface, then. I'd have to research jinja2 a bit to see what templating options are available.

@rlphillips
Copy link
Author

Hello! Alright, thanks for your feedback!

Since I'm not so experienced with Python and Jinja2 yet, I added bash to the mix, to get what I was working with reliably. But I understand it's not really in line with the philosophy of the repo.

It would probably be tidier to close this PR then, and if I get around to implementing this on Python I'll submit another one. I'll keep you posted, since I plan on regularly converting notebooks to Jekyll blog posts, based on this tool you introduce. I'll still comment and keep in mind your review requests for a future Python implementation.

As for a Docker solution with every step of the process, I'll start going in that direction, but it probably won't be completely fleshed out until I use it several times and run into some issues in order to make the solution more general.

We'll be in touch! Take care.

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.

2 participants