GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Docs + Launch hotfixes (#1272) · datapane/datapane@5ccad56

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • public-docs
    • Taskfile.yml
    • docs
      • apps
        • advanced.md
        • blocks.md
        • deployment.md
        • example.md
        • functions-controls.md
        • overview.md
        • updates.md
      • blocks
        • display-blocks.ipynb
        • image.png
        • layout-blocks.ipynb
        • netflix_stock_data.csv
        • overview.ipynb
      • deployment
        • local_apps.md
        • sharing_reports.md
      • features
        • reports.ipynb
      • index.ipynb
      • index.md
      • misc
        • cookbook.md
        • examples.md
        • installing-datapane.md
        • quickstart.ipynb
      • quickstart.ipynb
      • reference
        • display-blocks
          • data.ipynb
          • text.ipynb
        • layout-blocks
          • group.ipynb
          • select.ipynb
        • reports.md
      • reports
        • jupyter-integration.ipynb
        • overview.ipynb
        • styling.ipynb
    • mkdocs.yml
  • python-client
    • src/datapane
      • __init__.py
      • app
        • runtime.py
      • blocks
        • __init__.py
        • asset.py
        • base.py
        • layout.py
        • text.py
      • client
        • commands.py
        • utils.py
      • cloud_api
        • __init__.py
        • app.py
        • report.py
      • processors
        • __init__.py
        • api.py
        • processors.py
        • types.py
      • resources/view_resources
        • full_schema.rnc
        • full_schema.rng
      • view
        • asset_writers.py
        • view_blocks.py
        • visitors.py
        • xml_visitor.py
    • tests
      • client/views
        • test_views.py
      • conftest.py

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎public-docs/Taskfile.yml‎

Copy file name to clipboardExpand all lines: public-docs/Taskfile.yml
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ tasks:
2323
- cmd: poetry run ./nbbuild.sh
2424
- cmd: poetry run mkdocs build
2525

26+
build-docs-only:
27+
desc: "Locally build the docs only (don't run notebooks)"
28+
env:
29+
DATAPANE_CDN_BASE: '{{ .DATAPANE_CDN_BASE | default "" }}'
30+
cmds:
31+
- cmd: poetry run mkdocs build
32+
2633
build:inline-statics:
2734
desc: "Build a package ready for a deploy, with report statics loaded into the build"
2835
cmds:
Collapse file

‎…blic-docs/docs/features/apps/advanced.md‎ ‎public-docs/docs/apps/advanced.md‎public-docs/docs/features/apps/advanced.md renamed to public-docs/docs/apps/advanced.md public-docs/docs/features/apps/advanced.md renamed to public-docs/docs/apps/advanced.md

Copy file name to clipboardExpand all lines: public-docs/docs/apps/advanced.md
+30-26Lines changed: 30 additions & 26 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ import datapane as dp
1515
# a globally-accessible DataFrame
1616
df = data.iris()
1717

18-
def filter_df(params):
19-
return dp.DataTable(df[params['column']])
18+
def filter_df(column: str):
19+
return dp.DataTable(df[column])
2020

21-
app = dp.Blocks(
21+
blocks = dp.Blocks(
2222
dp.Form(
2323
on_submit=filter_df,
24-
controls=[dp.TextBox(name='name')]
24+
controls=dp.Controls(column = dp.Choice(options=list(df.columns), label="Select column to filter"))
2525
)
2626
)
27-
dp.serve_app(app)
27+
dp.serve_app(blocks)
2828
```
2929

3030
In the example above, `df` is referenced by `filter_df` and can be accessed in that function by all users when the function is called. It's important to note that Datapane supports multiple users by default, and Datapane will call ``filter_df` automatically for each user individually upon submitting the form.
3131

32-
... warning:
32+
!!! warning:
3333
Datapane apps support multiple users via threads, so normal considerations apply when modifying shared data structures across different threads
3434

3535
When shutting down the server, no state is preserved, this means that all users will lose any unsaved data and will need to reload their apps within the browser upon restarting the server again.
@@ -46,34 +46,35 @@ We have mentioned that a backend function receipts parameters as input and retur
4646
These are presented to the User in their App for performing further input that is in return sent to this __nested__ function - we term this _function chaining_. The functions defined and returned in these nested _Compute Blocks_ can be `lambdas`, previously defined / inline functions, and can, most importantly, refer to and capture existing variables in scope. This means it's possible to collect multiple pieces of input from a user, return per-user data, and even dynamically generate future input based on existing input - Python's dynamic nature makes quite advanced scenarios possible. This may be demonstrated best with an example,
4747

4848
```python
49+
from pathlib import Path
50+
import pandas as pd
4951
import datapane as dp
5052

51-
def load_file(file):
53+
def load_file(file: Path):
5254
# load the user's input into the file
53-
df = pd.load(file)
55+
df = pd.read_csv(file)
5456

55-
def process_df(col_name: str)
57+
def process_df(col_name: str):
5658
# a nested function which has access to `df` loaded in the previous interaction
57-
return df[col_name]
59+
return dp.DataTable(df[col_name])
5860

5961
return [
6062
df.describe(),
6163
# return a new Form that calls the nested function
62-
dp.Form(on_submit=process_df, controls=[col_name=dp.TextBoc()])
64+
dp.Form(on_submit=process_df, controls=dict(col_name=dp.TextBox()))
6365
]
6466

65-
app = dp.Blocks(
67+
blocks = dp.Blocks(
6668
dp.Form(
6769
on_submit=load_file,
68-
controls=[file=dp.File()]
70+
controls=dict(file=dp.File())
6971
)
7072
)
71-
dp.serve_app(app)
73+
dp.serve_app(blocks)
7274
```
7375

7476
In the above, the function chaining is isolated for each user, and uploaded `df` is stored independently to other users currently using the app.
7577

76-
7778
## Function Caching
7879

7980
Your backend function may perform complex calculations and thus take a long time to finish and/or is memory/compute intensive - this can slow down he performance of your app and frustrate users. To help, Datapane provides the ability to cache backend functions and reuse their results when called via a _Compute Block_.
@@ -90,19 +91,21 @@ import time
9091
import datapane as dp
9192

9293
# this function is cached when ever the same x and y values are seen
93-
def calc(params):
94+
def calc(x: int, y: int):
9495
time.sleep(1)
95-
return params['x'] * params['y']
96+
z = x+y
97+
return dp.BigNumber("Result", x+y)
9698

97-
app = dp.Blocks(
99+
blocks = dp.Blocks(
98100
dp.Form(
99101
on_submit=calc,
100-
controls=[dp.NumberBox('x'), dp.NumberBox('y', initial=0)],
101-
cache=True
102+
controls=[dp.NumberBox('x', initial=2), dp.NumberBox('y', initial=3)],
103+
cache=True,
104+
label="Add values"
102105
)
103106
)
104107

105-
dp.serve_app(app)
108+
dp.serve_app(blocks)
106109
```
107110

108111
## Session State
@@ -121,20 +124,21 @@ In the example below, we use the `session` variable to accumulate and modify a v
121124
```python
122125
import datapane as dp
123126

124-
def calc(params, session: dict):
127+
def calc(params: dict, session: dict):
125128
# read a value from the per user-session dict
126129
acc = session.get('acc', 0)
127130
result = params['x'] * params['y'] + acc
128131
# store back in the session
129132
session['acc'] = result
130-
return dp.Text(result)
133+
return dp.BigNumber("Result", result)
131134

132-
app = dp.Blocks(
135+
blocks = dp.Blocks(
133136
dp.Form(
134137
on_submit=calc,
135-
controls=[dp.NumberBox('x'), dp.NumberBox('y')],
138+
controls=[dp.NumberBox('x', initial=2), dp.NumberBox('y', initial=3)],
139+
label="Multiply and accumulate values to state",
136140
)
137141
)
138142

139-
dp.serve_app(app)
143+
dp.serve_app(blocks)
140144
```
Collapse file

‎public-docs/docs/features/apps/blocks.md‎ ‎public-docs/docs/apps/blocks.md‎public-docs/docs/features/apps/blocks.md renamed to public-docs/docs/apps/blocks.md

Copy file name to clipboardExpand all lines: public-docs/docs/apps/blocks.md
+10-12Lines changed: 10 additions & 12 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
Compute blocks, such as `dp.Form`, allow you to take parameters from end-users or update your app dynamically by triggering backend functions. When you add a Compute block, you specify a Python function which returns... you guessed it, blocks! The use of compute blocks require a running server, so won't they work in reports.
22

3-
43
## Forms
54

65
Build forms using [dp.Form][datapane.blocks.compute.Form], which expose controls, such as textboxes, file uploads, and number ranges. When a user submits the form, it runs the backend Python function you have chosen, and automatically updates the user's display with the result.
@@ -10,17 +9,17 @@ This means you can calculate complex analytics on demand in response to user inp
109
```python
1110
import datapane as dp
1211

13-
def f(params):
14-
first_name = params["first_name"]
12+
def f(first_name: str):
1513
return dp.Text(f"Hello, {first_name}!")
1614

17-
app = dp.Blocks(
15+
blocks = dp.Blocks(
1816
dp.Text("Welcome to my app"),
1917
dp.Form(on_submit=f,
20-
controls=dp.Controls(first_name=dp.TextBox())),
18+
controls=dp.Controls(first_name=dp.TextBox()),
19+
label="Enter your name:"),
2120
)
2221

23-
dp.serve_app(app)
22+
dp.serve_app(blocks)
2423
```
2524

2625
You typically provide `dp.Form` with two parameters:
@@ -42,16 +41,15 @@ In the example below, the `on_load` parameter to `dp.Dynamic` - this instructs t
4241
from datetime import datetime
4342
import datapane as dp
4443

45-
def get_time():
46-
return dp.Text(datetime.now().time().isoformat())
44+
def get_time() -> str:
45+
return datetime.now().time().isoformat()
4746

48-
app = dp.Blocks(
49-
dp.Text(f"This app was created at {get_time()}"),
50-
dp.Text("The current time is ..."),
47+
blocks = dp.Blocks(
48+
dp.Text(f"This app was created at {get_time()},\n the app was loaded at..."),
5149
dp.Dynamic(on_load=get_time)
5250
)
5351

54-
dp.serve_app(app)
52+
dp.serve_app(blocks)
5553
```
5654

5755
`dp.Dynamic` also has an `on_timer` parameter which can be used to call a backend function on a regular schedule - see the [API docs][datapane.blocks.compute.Dynamic] for more information.
Collapse file

‎…ic-docs/docs/deployment/deployed_apps.md‎ ‎public-docs/docs/apps/deployment.md‎public-docs/docs/deployment/deployed_apps.md renamed to public-docs/docs/apps/deployment.md public-docs/docs/deployment/deployed_apps.md renamed to public-docs/docs/apps/deployment.md

Copy file name to clipboardExpand all lines: public-docs/docs/apps/deployment.md
+30-1Lines changed: 30 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
1+
You can host a Datapane app from inside your current Python environment, whether that's your local machine, or a hosted notebook like Colab or Databricks.
2+
3+
## Local App Serving
4+
5+
To host your app, run `dp.serve_app`.
6+
7+
!!! note
8+
A port will be chosen automatically, but you can manually specify `port` and `host`.
9+
10+
```python
11+
import datapane as dp
12+
13+
app = dp.Blocks(...)
14+
15+
dp.serve_app(app)
16+
```
17+
18+
### Creating a public URL
19+
20+
Datapane has built-in support for ngrok, which allows you to create a public, shareable URL for your data app. Simply add `public=True` to your serve command. This will prompt you to enter your ngrok token, and will return a URL which you can share.
21+
22+
```python
23+
dp.serve_app(app, public=True)
24+
```
25+
26+
### Embed mode
27+
28+
If you are embedding your app in a third-party product, you will need to pass `embed_mode=True` to `dp.serve`. This disables specific security policies which will not work within an `iframe`.
29+
130
## Datapane Cloud
231

3-
Datapane Cloud will shortly provide App hosting specific and optimised to the needs of App running and hosting, including access-controls, security and authentication features that organisations require.
32+
Datapane Cloud will shortly provide App hosting specific and optimized to the needs of App running and hosting, including access-controls, security and authentication features that organizations require.
433

534
At the same time, you can easily host your app via any web server hosting service (especially those that work with Python / WSGI-based apps), including the services listed here.
635

Collapse file

‎public-docs/docs/features/apps/example.md‎ ‎public-docs/docs/apps/example.md‎public-docs/docs/features/apps/example.md renamed to public-docs/docs/apps/example.md

Copy file name to clipboardExpand all lines: public-docs/docs/apps/example.md
+15-22Lines changed: 15 additions & 22 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,41 @@
1-
# An example app
2-
3-
This example demonstrates an app that allows the user to visualise different dimensions of the Iris flower dataset.
4-
1+
This example demonstrates an app that allows the user to visualize different dimensions of the Iris flower dataset.
52

63
```python
4+
import random
75
import altair as alt
86
import datapane as dp
97
from vega_datasets import data
108

9+
# load the dataset as a global value
1110
dataset = data.iris()
1211
columns = list(dataset.columns)
1312

14-
15-
def plot(params):
16-
global dataset
17-
13+
def plot(x_axis: str, y_axis: str, color: str) -> dp.Plot:
14+
"""Create and return the plot"""
1815
fig = (
1916
alt.Chart(dataset)
2017
.mark_point()
2118
.encode(
22-
x=alt.X(params["x_axis"], scale=alt.Scale(zero=False)),
23-
y=alt.X(params["y_axis"], scale=alt.Scale(zero=False)),
24-
color=params["color"],
19+
x=alt.X(x_axis, scale=alt.Scale(zero=False)),
20+
y=alt.X(y_axis, scale=alt.Scale(zero=False)),
21+
color=color,
2522
tooltip=columns,
2623
)
2724
)
2825

29-
return dp.Plot(fig, name="plot")
30-
31-
32-
plot({"x_axis": "sepalLength", "y_axis": "sepalWidth", "color": "species"})
26+
return dp.Plot(fig)
3327

28+
# App setup
3429
controls = dp.Controls(
35-
dp.Choice("x_axis", options=columns),
36-
dp.Choice("y_axis", options=columns),
37-
dp.Choice("color", options=columns),
30+
dp.Choice("x_axis", options=columns, initial=random.choice(columns)),
31+
dp.Choice("y_axis", options=columns, initial=random.choice(columns)),
32+
dp.Choice("color", options=columns, initial=random.choice(columns)),
3833
)
39-
40-
v = dp.Blocks(
34+
blocks = dp.Blocks(
4135
"# Iris Dataset Plotter",
4236
dp.Form(plot, submit_label="Plot", controls=controls),
4337
)
44-
45-
dp.serve_app(v)
38+
dp.serve_app(blocks)
4639
```
4740

4841
<!-- We've deployed the app to Fly.io using our [deployment docs](/deployment/deployed_apps/). You can view it here:
Collapse file

‎…docs/features/apps/functions_controls.md‎ ‎…lic-docs/docs/apps/functions-controls.md‎public-docs/docs/features/apps/functions_controls.md renamed to public-docs/docs/apps/functions-controls.md public-docs/docs/features/apps/functions_controls.md renamed to public-docs/docs/apps/functions-controls.md

Copy file name to clipboardExpand all lines: public-docs/docs/apps/functions-controls.md
+3-4Lines changed: 3 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,11 @@ dp.Form(on_submit=f,
4242

4343
### Returning Values
4444

45-
Datapane functions can return any [Datapane block](../display_blocks.ipynb) or [raw Python objects](../display_blocks.ipynb#automatic-conversion) that are supported by Datapane. You can return these directly, as a list, or return a layout or container block like `dp.Blocks` or `dp.Group` for a more advanced layout.
45+
Datapane functions can return any [Datapane block](../blocks/display-blocks.ipynb) or [raw Python objects](../blocks/display-blocks.ipynb#automatic-conversion) that are supported by Datapane. You can return these directly, as a list, or return a layout or container block like `dp.Blocks` or `dp.Group` for a more advanced layout.
4646

4747
!!! tip
4848
You can even return compute blocks like `dp.Form` and `dp.Dynamic` from a function, allowing you to chain functions together that build more complex operations and interactive apps, such as wizards.
4949

50-
5150
## Controls
5251

5352
Controls are used to define the specific parameters to present to the user for input, such as a `TextField`, a number `Range`, or even a `File` upload.
@@ -56,7 +55,7 @@ These parameters are collected from the user and passed by Datapane into the res
5655

5756
When the user submits the form, Datapane automatically handles uploading the user's input, validates it, converts it to the correct type, and provides initial values if none are given. From there, Datapane calls the Compute function with the params in the `params` dict as mentioned [above](#compute-functions).
5857

59-
When adding a Compute Block to your code, you pass in the collection of parameters that make up your contols via a `dp.Controls` object.
58+
When adding a Compute Block to your code, you pass in the collection of parameters that make up your controls via a `dp.Controls` object.
6059

6160
```python
6261
dp.Form(on_submit=f,
@@ -89,4 +88,4 @@ The built-in parameters include,
8988
| [DateTime][datapane.blocks.parameters.DateTime] | `datetime.datetime` | Select a date and a time |
9089
| [File][datapane.blocks.parameters.File] | `pathlib.Path`| Upload a file |
9190

92-
The [Controls API docs](../../reference/apps/controls.ipynb) also include detailed information and live samples of each parameter type.
91+
The [Controls API docs](../reference/apps/controls.ipynb) also include detailed information and live samples of each parameter type.
Collapse file

‎…-docs/docs/features/apps/introduction.md‎ ‎public-docs/docs/apps/overview.md‎public-docs/docs/features/apps/introduction.md renamed to public-docs/docs/apps/overview.md public-docs/docs/features/apps/introduction.md renamed to public-docs/docs/apps/overview.md

Copy file name to clipboardExpand all lines: public-docs/docs/apps/overview.md
+9-9Lines changed: 9 additions & 9 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@ In just a few lines we have built a simple data app that allows multiple users t
1212
from vega_datasets import data
1313
import datapane as dp
1414

15+
# a globally-accessible DataFrame
1516
df = data.iris()
1617

17-
def filter_df(params):
18+
def filter_df(column: str):
1819
# Our dynamic function
19-
return dp.DataTable(df[params['column']])
20+
return dp.DataTable(df[column])
2021

2122
# We define the App similar to a Report
22-
app = dp.Blocks(
23+
blocks = dp.Blocks(
2324
dp.Form(
2425
on_submit=filter_df,
25-
controls=[dp.TextBox(name='name')]
26+
controls=dp.Controls(column=dp.Choice(options=list(df.columns), label="Select column to filter"))
2627
)
2728
)
2829

2930
# Start serving the app (by default on http://localhost:8000)
30-
dp.serve_app(app)
31+
dp.serve_app(blocks)
3132
```
3233

3334
<!-- TODO - embed this app... -->
@@ -36,10 +37,9 @@ dp.serve_app(app)
3637

3738
Apps build upon Reports and add a few simple concepts to make them dynamic:
3839

39-
- [Compute Blocks](./blocks.md), such as [dp.Form][datapane.blocks.compute.Form] and [dp.Dynamic][datapane.blocks.compute.Dynamic] are added to your app alongside any static [Display](../display_blocks.ipynb) and [Layout](../layout_blocks.ipynb) blocks, and provide the interface into backend functions.
40-
- [Parameters](./functions_controls.md), such as [dp.TextBox][datapane.blocks.parameters.TextBox] above, and more complex controls such as [dp.Range][datapane.blocks.parameters.Range], provide an interactive set of Controls to use in your Forms in order to allow your viewers to specify parameters.
41-
- [Backend functions](./functions_controls.md), such as `filter_df` above, take these parameters, run any processing needed, and return Display and Layout blocks.
42-
40+
- [Compute Blocks](./blocks.md), such as [dp.Form][datapane.blocks.compute.Form] and [dp.Dynamic][datapane.blocks.compute.Dynamic] are added to your app alongside any static [Display](../blocks/display-blocks.ipynb) and [Layout](../blocks/layout-blocks.ipynb) blocks, and provide the interface into backend functions.
41+
- [Parameters](./functions-controls.md), such as [dp.TextBox][datapane.blocks.parameters.TextBox] above, and more complex controls such as [dp.Range][datapane.blocks.parameters.Range], provide an interactive set of Controls to use in your Forms in order to allow your viewers to specify parameters.
42+
- [Backend functions](./functions-controls.md), such as `filter_df` above, take these parameters, run any processing needed, and return Display and Layout blocks.
4343

4444
Most other data app frameworks work by running your app from top to bottom every time something changes.
4545

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.