Creating Simple Interactive Forms Using Python + Markdown Using ScriptedForms + Jupyter

Just… wow…

Every time I miss attending the OER conf (which is most years, which is stupid because all the best peeps are there) I try to assuage my guilt by tinkering with some OpenLearn stuff.

This year, I revisted my OpenLearn XML scraper – first sketch notebook here – scraping the figure data into a SQLite db that I then popped onto Heroku as a datasette (a single command line command – datasette publish heroku openlearn.sqlite posts the sqlite database to Heroku as a running app, so thanks to Simon Willison, it’s not hard, right?).

That’s okay as far as it goes – there are some notes in the notebook about more nuggets that can be pulled from the OpenLearn OU-XML – but it falls short of giving a demo gallery of images.

The latest version of datasette supports plugins, as well as the original templating, which means I should be able to put together a simple gallery viewer, allowing figure caption / description data to be searched then showing the results with the corresponding images alongside. But there’s still learning for me to be done there (I still don’t grok jinja templates) and I wanted a quick win…

Tinkering with Simon Biggs’ ScriptedForms Jupyter hack has been on my to do list for a bit, and with its markdown + python interactive app scripting, it looked like it contained the promise of a quick win. And it did…

For example, here’s a markdown script in a file openlearnq.md:

# OpenLearn Images


```python

from IPython.display import Image

import pandas
import sqlite3
conn = sqlite3.connect('openlearn.sqlite')
```




image_text
```python
q="SELECT * FROM xmlfigures WHERE caption LIKE '%{q}%' LIMIT 10".format(q=image_text)
pd.read_sql(q, conn)
#UPDATE: I've found more recently I need: display(pd.read_sql(q, conn))
```

and here’s the running app (launched from the command line as scriptedforms openlearnq.md).

I have a github repo here to try to run this via Binderhub: Binder

PS as to setting up the github repo, it was done without git: the repo was created online,  the binder/ dir files (cribbed from SimonBiggs/scriptedforms-examples) were created and edited onlin evia the Github web UI, the openlearn-example.md and openlearn.sqlite files were automatically uploaded once I’d dragged from my desktop onto the repo web page, leaving it to me to just commit them (which I forgot the first time!). See also: Easy Web Publishing With Github

PPS I’m also wondering if it would be possibly to run datasette in the same Binder container and then query the sqlite db via the datasette API service?

Author: Tony Hirst

I'm a Senior Lecturer at The Open University, with an interest in #opendata policy and practice, as well as general web tinkering...