Jupyter Notebook provides developers with a highly interactive work environment for algorithm validation, visual analysis, model debugging, and other scenarios. However, in server-based deployments, especially when developing remotely using Jupyter, efficiently exporting Notebook results for presentation, archiving, sharing, or production reporting is a crucial skill. So, how can you export Jupyter Notebook results as static files, screenshots, or even create interactive documents to help operations, development, and analysis personnel efficiently process data?
Prerequisites for Deploying Jupyter Notebook on a Server
Before proceeding with the export process, ensure that the Jupyter Notebook environment has been correctly deployed on the server and supports the necessary export components. For example, on Ubuntu or CentOS, the recommended installation method is:
pip install jupyterlab nbconvert ipywidgets
To generate PDF or interactive HTML reports, we recommend installing LaTeX and pandoc:
sudo apt install texlive-xetex pandoc
On a remote server, it's recommended to bind Jupyter to a public network port (be sure to set a password or token). The configuration file is typically located in ~/.jupyter/jupyter_notebook_config.py.
Screenshot Export: Suitable for quick demonstrations and report summaries.
A straightforward method (and the recommended one) is to take screenshots in your browser. After running Jupyter on the server, access the screenshots through a browser. Another method is to automatically take screenshots of your code. To automatically generate output screenshots from your code (especially useful for image data analysis), you can use the following method with matplotlib or plotly:
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.savefig('output.png')
The image will be automatically saved in the current directory on the server for further processing or downloading. If you want to export to static formats like HTML, PDF, and Markdown, Jupyter Notebook natively supports exporting to various formats using nbconvert. The operation path is as follows:
1. Export from the web interface:
Click File > Download as in the menu bar. Supported formats include:
HTML (suitable for direct viewing or emailing)
PDF (for archiving formal reports)
Markdown (suitable for embedding in static blogs or documents)
Python script (convert to .py source code)
Notebook (save as .ipynb)
2. Export from the command line:
In the server SSH terminal, execute:
jupyter nbconvert --to html my_notebook.ipynb
jupyter nbconvert --to pdf my_notebook.ipynb
jupyter nbconvert --to markdown my_notebook.ipynb
To include the output, add the --execute parameter:
jupyter nbconvert --to html --execute my_notebook.ipynb
For interactive data presentations (such as sliders and drop-down menus), exporting only to an HTML file will not preserve the interactive logic. In this case, you will need to use tools such as voilà to build interactive pages.
Install voila (recommended for remote use on a GPU or compute server).
pip install voila
Start the interactive notebook server
voila my_notebook.ipynb
This command will start a web server on the server that only displays output (code blocks are automatically hidden). It's ideal for product demonstrations or data reporting. Combined with an Nginx reverse proxy, it can be deployed as an enterprise-grade web dashboard. Expose the server port as a fixed domain path using the following method, which can be embedded in the business frontend:
location /report/ {
proxy_pass http://127.0.0.1:8866/;
proxy_set_header Host $host;
}
Common Notebook Export Errors and Fixes
Problem 1: PDF export fails with a message stating that xelatex cannot be found
Solution: Ensure LaTeX is fully installed on the server:
sudo apt install texlive-xetex texlive-fonts-recommended texlive-latex-recommended
Problem 2: Interactive charts do not work in HTML
If using libraries such as plotly or bokeh, be sure to add the following before executing:
import plotly.offline as py
py.init_notebook_mode(connected=True)
Use plotly.offline.iplot() to ensure that interactive charts are embedded in the notebook.
Additional Recommendation: Automated Batch Export Script
To batch generate Notebook reports on enterprise servers, you can use the following automated script:
for file in *.ipynb
do
jupyter nbconvert --execute --to html "$file"
done
Execute and export all Notebooks to HTML. This can be combined with crontab to generate reports on a daily schedule.
As one of the most important interactive development platforms in cloud server environments, Jupyter Notebook's export functionality directly impacts the efficiency and quality of data output. From screenshots to PDFs, from static HTML to interactive output, different export methods cater to different business scenarios. Whether for scientific research, AI deployment, or back-end data reporting, mastering these export techniques is a critical skill for every server engineer and data analyst.