From 10cdef9a10acefce9658ecaa3db2a9fe126c2d80 Mon Sep 17 00:00:00 2001 From: Richard Darst Date: Mon, 6 Nov 2023 00:21:30 +0200 Subject: [PATCH] Thebe: demonstrate Thebe to run code inline - Don't merge: this is a demo. - This includes the Pandas pull request, but is unrelated. Diff will look better once that is merged. - A "Launch" button appears at the top - Then, it launches a kernel on mybinder.org in the default jupyter data sci repo (todo: does this have everything this course needs?). - Then, you can click "run" on any cell and see the output (just like Jupyter would look), also edit the code and re-run. - Formatting is a bit off (line spacing is too much, probably since this uses sphinx_rtd_theme). - I don't think we should use this for 2023 (not unless there is more testing and maybe an own mybinder instance...), but hopefully it's a good demo. --- content/conf.py | 7 +++++++ content/pandas.rst | 2 ++ requirements.txt | 1 + 3 files changed, 10 insertions(+) diff --git a/content/conf.py b/content/conf.py index 5ef85587..04c8575f 100644 --- a/content/conf.py +++ b/content/conf.py @@ -40,9 +40,16 @@ 'sphinx.ext.mathjax', 'sphinx_aaltoscicomp_branding', 'sphinxext.opengraph', + 'sphinx_thebe', ] myst_enable_extensions = ['colon_fence'] +thebe_config = { + "selector": "div.highlight" +} + +nb_execution_mode = "off" + ogp_site_name = "Python for Scientific Computing" ogp_site_url = 'https://aaltoscicomp.github.io/python-for-scicomp/' import datetime diff --git a/content/pandas.rst b/content/pandas.rst index 10f97f80..e2b2ec20 100644 --- a/content/pandas.rst +++ b/content/pandas.rst @@ -33,6 +33,8 @@ material, including: A quick Pandas preview ---------------------- +.. thebe-button:: + Let's get a flavor of what we can do with pandas (you won't be able to follow everything yet). We will be working with an example dataset containing the passenger list from the Titanic, which is often used in Kaggle competitions and data science tutorials. First step is to load pandas:: import pandas as pd diff --git a/requirements.txt b/requirements.txt index 0477043c..695dd323 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,7 @@ sphinx-lesson https://github.com/aaltoscicomp/sphinx-aaltoscicomp-branding/archive/master.zip sphinx_rtd_theme_ext_color_contrast sphinxext-opengraph +sphinx-thebe # for web-apis execution jsonlines