Files
serena/docs/02_notebooks/01_library_example.ipynb
T
2025-03-23 23:33:19 +01:00

129 lines
3.4 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# The role of notebooks\n",
"\n",
"Notebooks are great for illustrations and examples that at the same time serve as integration tests.\n",
"In this library template, notebooks will be executed with pytest (thus on every\n",
"commit in your CI/CD pipeline). The results of the executions will be saved to the docs directory and converted to\n",
"static websites through nbconvert. The static websites are then added to the documentation under the\n",
"_Guides and Tutorials_ section. These websites will be deployed to Github pages on push to develop."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Before running the notebook\n",
"\n",
"Install the library and its dependencies with, if you haven't done so already\n",
"```\n",
"poetry install\n",
"```\n",
"from the root directory. You can also execute this command directly in the notebook but will need to reload the\n",
"kernel afterwards"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"# Here an illustration of your library\n",
"from serena.sample_package.sample_module import hello_stranger\n",
"\n",
"hello_stranger()"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"## Interactive Documentation\n",
"\n",
"Note that since notebooks are rendered to html+javascript, you can embed interactive components like maps, videos and\n",
"widgets into your documentation, as long as the interaction does not require re-execution of cells.\n",
"Below an example of an interactive map created with plotly {cite}`PlotlyMaps`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"# slightly adjusted example from https://plotly.com/python/mapbox-layers/\n",
"import pandas as pd\n",
"import plotly.express as px\n",
"\n",
"us_cities = pd.read_csv(\n",
" \"https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv\",\n",
")\n",
"\n",
"fig = px.scatter_mapbox(\n",
" us_cities,\n",
" lat=\"lat\",\n",
" lon=\"lon\",\n",
" hover_name=\"City\",\n",
" hover_data=[\"State\", \"Population\"],\n",
" color_discrete_sequence=[\"fuchsia\"],\n",
" zoom=3,\n",
" height=300,\n",
")\n",
"\n",
"fig.update_layout(mapbox_style=\"open-street-map\", margin={\"r\": 0, \"t\": 0, \"l\": 0, \"b\": 0})\n",
"fig.show()"
]
},
{
"cell_type": "markdown",
"source": [
"```{bibliography}\n",
":style: unsrtalpha\n",
":filter: docname in docnames\n",
"```"
],
"metadata": {
"collapsed": false
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}