From c42ab0e953e02ba6c36ddf251de1fb2dc3d68079 Mon Sep 17 00:00:00 2001 From: MarcSkovMadsen Date: Thu, 22 Feb 2024 19:07:55 +0000 Subject: [PATCH] improve language --- doc/how_to/server/commandline.md | 2 +- doc/tutorials/basic/serve.md | 98 +++++++++----------------------- 2 files changed, 28 insertions(+), 72 deletions(-) diff --git a/doc/how_to/server/commandline.md b/doc/how_to/server/commandline.md index 39518c7aea..10b2baa7bc 100644 --- a/doc/how_to/server/commandline.md +++ b/doc/how_to/server/commandline.md @@ -1,4 +1,4 @@ -# Launch a server on the commandline +# Launch a server on the command line Once the app is ready for deployment it can be served using the Bokeh server. For a detailed breakdown of the design and functionality of Bokeh server, see the [Bokeh documentation](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html). The most important thing to know is that Panel (and Bokeh) provide a CLI command to serve a Python script, app directory, or Jupyter notebook containing a Bokeh or Panel app. To launch a server using the CLI, simply run: diff --git a/doc/tutorials/basic/serve.md b/doc/tutorials/basic/serve.md index 3cc27a729a..64f79768c6 100644 --- a/doc/tutorials/basic/serve.md +++ b/doc/tutorials/basic/serve.md @@ -1,21 +1,17 @@ # Build Hello World App -In this tutorial, we will develop and *serve* a *Hello World* Panel: - -- Serve the app with `panel serve app.py` or `panel serve app.ipynb`. -- serve with auto reload by adding the flag `--autoreload`. -- stop your server with `CTRL+C`. +Welcome to the "Build Hello World App" tutorial! Get ready to dive into the world of Panel and serve your very first app. ## Serve the App -Select a *tab* below and continue +Let's get started by serving our simple *Hello World* app using Panel. Choose a tab below to continue: :::::{tab-set} -::::{tab-item} Python Script +::::{tab-item} Script :sync: script -The simplest Panel `.py` app could look like this: +In this section, we'll create the simplest Panel `.py` app: ```python import panel as pn @@ -26,41 +22,31 @@ pn.panel("Hello World").servable() ``` :::{note} -The code refers to +Here's a breakdown of the code: -- `panel`: The Panel python package. It's a convention to import it as `pn`. +- `panel`: The Panel python package, conventionally imported as `pn`. - `pn.extension()`: Loads javascript dependencies and configures Panel. - `pn.panel(...)`: Creates a *displayable* Panel component. - `.servable()`: Displays the component in a *server app*. ::: -Copy the code into a file named `app.py`. - -Save the file. - -Run the Panel server in your terminal with +Copy the code into a file named `app.py` and save it. Then, run the Panel server in your terminal with: ```bash panel serve app.py --autoreload ``` -When the server has started, the terminal output should look like this +Upon successful startup, you'll see the server's URL in the terminal. ```bash -$ panel serve app.py --autoreload 2024-01-17 15:49:11,443 Starting Bokeh server version 3.3.2 (running on Tornado 6.3.3) 2024-01-17 15:49:11,444 User authentication hooks NOT provided (default user enabled) 2024-01-17 15:49:11,450 Bokeh app running at: http://localhost:5006/app 2024-01-17 15:49:11,450 Starting Bokeh server with process id: 47256 ``` -:::{note} -The command `panel serve app.py --autoreload` refers to: +Open your browser at that URL to view the app. -- `panel`: the panel executable. -- `serve`: the command you want Panel to run -- `app.py`: the file `app.py` you want to serve -- `--autoreload`: make the server restart after code changes. Use this for **development only**. ::: :::: @@ -68,7 +54,7 @@ The command `panel serve app.py --autoreload` refers to: ::::{tab-item} Notebook :sync: notebook -The simplest Panel Notebook app could look like this: +In this section, we'll create the simplest Panel Notebook app: ```python import panel as pn @@ -81,82 +67,50 @@ pn.panel("Hello World").servable() ``` :::{note} -The code refers to +Here's what the code does: -- `panel`: The Panel python package. It's a convention to import it as `pn`. +- `panel`: The Panel python package, conventionally imported as `pn`. - `pn.extension()`: **Loads the [`pyviz_comms`](https://github.com/holoviz/pyviz_comms) notebook extension**, loads javascript dependencies and configures Panel. -- `pn.panel(...)`: Creates a *displayable* Panel component. **The component can be displayed directly in the notebook**. +- `pn.panel(...)`: Creates a *displayable* Panel component, which can be directly displayed in the notebook. - `.servable()`: Displays the component in a *server app*. ::: -Copy the 2 code cells above into a clean notebook named `app.ipynb`. - -Run the cells in the notebook and save it as `app.ipynb` if you have not already done it. - -It should look like +Copy the above code cells into a clean notebook named `app.ipynb`. Run the cells and save the notebook as `app.ipynb`. -![Panel Notebook App](../../_static/images/panel-serve-ipynb-notebook.png). - -Run the Panel server in your terminal with +Then, run the Panel server in your terminal with: ```bash panel serve app.ipynb --autoreload ``` -When the server has started, the terminal output should look like this +Upon successful startup, you'll see the server's URL in the terminal. ```bash -$ panel serve app.ipynb --autoreload 2024-01-17 21:05:32,338 Starting Bokeh server version 3.3.3 (running on Tornado 6.4) 2024-01-17 21:05:32,339 User authentication hooks NOT provided (default user enabled) 2024-01-17 21:05:32,342 Bokeh app running at: http://localhost:5006/app 2024-01-17 21:05:32,342 Starting Bokeh server with process id: 42008 ``` -:::{note} -The command `panel serve app.ipynb --autoreload` refers to: +Open your browser at that URL to view the app. -- `panel`: the panel executable. -- `serve`: the command you want Panel to run -- `app.ipynb`: the file `app.ipynb` you want to serve -- `--autoreload`: make the server restart after code changes. Use this for **development only**. ::: -:::: - ::::: -In the output, you will find the line - -```bash -Bokeh app running at: http://localhost:5006/app -``` - -That line shows the URL where your app is being served, on your local machine. - -:::{note} -The `Bokeh server` is mentioned because Panel is built on top of [Bokeh](https://docs.bokeh.org). -::: +Once the server is running, you'll see the app displayed in your browser. It should look like -Open your browser at [http://localhost:5006/app](http://localhost:5006/app). +![Panel serve app](../../_static/images/panel-serve-py-app.png). -The application will look like. - -![Panel serve single .py file](../../_static/images/panel-serve-py-app.png). - -Try changing `"Hello World"` to `"World Hello"`. - -Save the file. The application will automatically reload and show the updated text. - -Now stop the server by pressing `CTRL+C` one or more times in the terminal. +Play around with the app by modifying the text, saving the file and observe how it updates in real-time. To stop the server, simply press `CTRL+C` in the terminal. ## Recap -Congratulations. We have just served our first Panel app. Along the way, we have learned to +Congratulations on serving your first Panel app! Let's recap what we've learned: -- serve a Python script or Notebook with the commands `panel serve app.py` or `panel serve app.ipynb` respectively. -- serve with *auto reload* by adding the flag `--autoreload`. -- stop the Panel server with `CTRL+C`. +- How to serve a Python script or Notebook using `panel serve app.py` or `panel serve app.ipynb`, respectively. +- How to enable *auto reload* with the `--autoreload` flag. +- How to stop the Panel server with `CTRL+C`. ## Resources @@ -167,7 +121,7 @@ Congratulations. We have just served our first Panel app. Along the way, we have ### How-to - [Launch a server dynamically with `pn.serve` or `pn.show`](../../how_to/server/programmatic.md) -- [Launch a server on the commandline](../../how_to/server/commandline.md) +- [Launch a server on the command line](../../how_to/server/commandline.md) - [Migrate from Streamlit | Serve Apps](../../how_to/streamlit_migration/index.md) - [Serve multiple applications with `pn.serve`](../../how_to/server/multiple.md) - [Serve static files with `--static-dirs`](../../how_to/server/static_files.md) @@ -175,3 +129,5 @@ Congratulations. We have just served our first Panel app. Along the way, we have - [Serve with FastAPI](../../how_to/integrations/FastAPI.md) - [Serve with Flask](../../how_to/integrations/flask.md) - [Write and serve apps in Markdown](../../how_to/editor/markdown.md) + +Keep exploring and building with Panel! 🚀