Skip to content

Commit

Permalink
improve language
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcSkovMadsen committed Feb 22, 2024
1 parent 1afb170 commit c42ab0e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 72 deletions.
2 changes: 1 addition & 1 deletion doc/how_to/server/commandline.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
98 changes: 27 additions & 71 deletions doc/tutorials/basic/serve.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,49 +22,39 @@ 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**.
:::

::::

::::{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
Expand All @@ -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

Expand All @@ -167,11 +121,13 @@ 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)
- [Serve with Django](../../how_to/integrations/Django.md)
- [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! 🚀

0 comments on commit c42ab0e

Please sign in to comment.