Skip to content

Commit 7ce2e34

Browse files
committed
Fixed links
1 parent a59e1e1 commit 7ce2e34

File tree

2 files changed

+120
-16
lines changed

2 files changed

+120
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ or other programming languages.
77
It comprises a [Python backend package](chartlets.py/README.md)
88
and a [JavaScript/React frontend package](chartlets.js/README.md).
99

10-
Please see the [Documentation]() for more information.
10+
Please see the [Documentation](https://bcdev.github.io/chartlets/) for more information.
1111

1212
## Features
1313

docs/usage.md

Lines changed: 119 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,120 @@
1-
This chapter describes how to enhance your web application by server-side
2-
UI-contributions.
1+
The Chartlets framework has two types of users.
32

4-
The chartlets backend implementation is provided by the Python package `chartlets`.
5-
It makes it easy to implement the chartlet endpoints in your preferred
6-
webserver framework, such as Flask, FastAPI, or Tornado.
3+
- **Application contributors** develop new contributions for a specific web application.
4+
- **Application providers** develop the web application and the service that allows
5+
for server-side UI contributions.
76

8-
### 1. Implement the possible contributions
7+
8+
## Application contributor guide
9+
10+
As a application contributors you develop a Python module that is consumed by
11+
the application's backend service.
12+
13+
Your module is supposed to export one or more instances of the
14+
`chartlets.Extension` class. An extension object is a container for your
15+
UI contributions. It groups contributions that logically belong together.
16+
17+
As an example, see [`my_extension` of the demo](https://github.com/bcdev/chartlets/tree/main/chartlets.py/my_extension).
18+
19+
To develop an extension, follow these steps:
20+
21+
1. Create the extension object
22+
2. Create the contribution object
23+
3. Implement the contribution layout
24+
4. Implement the contribution callbacks
25+
5. Register the contribution
26+
27+
In the following the above steps are detailed further.
28+
29+
### Create the extension object
30+
31+
Your contributions to the application are published using a
32+
`chartlets.Extension` object that is exported from your extension module.
33+
34+
```python
35+
from chartlets import Extension
36+
37+
ext = Extension("my_dashboard")
38+
```
39+
40+
### Create the contribution object
41+
42+
In a submodule you create a contribution object from an application specific
43+
contribution, e.g., a `Panel`. Application-specific contribution classes
44+
are always derived from `chartlets.Contribution`.
45+
46+
```python
47+
from chartlets.demo import Panel
48+
49+
panel = Panel(title="Click Statistics")
50+
```
51+
52+
### Implement the contribution layout
53+
54+
In the submodule
55+
56+
```python
57+
@panel.layout()
58+
def get_layout(ctx):
59+
return Button(id="button", text="Click me")
60+
```
61+
62+
### Implement the contribution callback
63+
64+
In the submodule
65+
66+
```python
67+
from chartlets import Import, Output
68+
69+
@panel.callback(
70+
Input("button", "n_clicks"),
71+
Output("button", "text")
72+
)
73+
def on_button_click(ctx, n_clicks):
74+
n = n_clicks + 1
75+
s = {1: "st", 2: "nd", 3: "rd"}.get(n, "th")
76+
return f"Click me a {n}{s} time"
77+
```
78+
79+
### Register the contribution
80+
81+
In the extension module
82+
83+
```python
84+
from chartlets import Extension
85+
from .stats_panel import panel as stats_panel
86+
87+
ext = Extension("my_dashboard")
88+
ext.add(stats_panel)
89+
```
90+
91+
## Application provider guide
92+
93+
As an application provider you allow for enhancing your web application by
94+
server-side UI-contributions provided by an application contributor.
95+
96+
The Chartlets backend implementation is provided by the Python module
97+
`chartlets.controllers`.
98+
It makes it easy to implement the Chartlet endpoints in your preferred
99+
webserver framework, such as Flask, FastAPI, or Tornado.
100+
101+
The following steps are required to enable your web server to support
102+
UI-contributions:
103+
104+
1. Implement the possible contributions
105+
2. Define the contributions points
106+
3. Load the extensions
107+
4. Publish the extensions
108+
5. Consume the extensions
109+
110+
In the following the above steps are detailed further.
111+
112+
### Implement the possible contributions
9113

10114
Implement the application-specific contributions that users
11115
can add to their extensions.
12116

13-
As an example, see [`panel.py` of the demo](chartlets.py/chartlets/demo/contribs/panel.py):
117+
As an example, see [`panel.py` of the demo](https://github.com/bcdev/chartlets/tree/main/chartlets.py/chartlets/demo/contribs/panel.py):
14118

15119
```python
16120
from chartlets import Contribution
@@ -23,11 +127,11 @@ class Panel(Contribution):
23127
super().__init__(name, title=title)
24128
```
25129

26-
### 2. Define the contributions points
130+
### Define the contributions points
27131

28132
Define the possible contribution points in your application.
29133

30-
As an example, see [`server.py` of the demo](chartlets.py/chartlets/demo/server.py):
134+
As an example, see [`server.py` of the demo](https://github.com/bcdev/chartlets/tree/main/chartlets.py/chartlets/demo/server.py):
31135

32136
```python
33137
from chartlets import Extension
@@ -36,28 +140,28 @@ from chartlets.demo.contribs import Panel
36140
Extension.add_contrib_point("panels", Panel)
37141
```
38142

39-
### 3. Load the extensions
143+
### Load the extensions
40144

41145
Load the extensions that augment your application.
42146

43-
As an example, see [`server.py` of the demo](chartlets.py/chartlets/demo/server.py):
147+
As an example, see [`server.py` of the demo](https://github.com/bcdev/chartlets/tree/main/chartlets.py/chartlets/demo/server.py):
44148

45149
```python
46150
from chartlets import ExtensionContext
47151

48152
ext_ctx = ExtensionContext.load(app_ctx, extension_refs)
49153
```
50154

51-
### 4. Publish the extensions
155+
### Publish the extensions
52156

53157
Implement the Chartlets API in your application-specific webserver using
54158
the controller implementations in `chartlets.controllers`.
55159

56-
As an example, see [`server.py` of the demo](chartlets.py/chartlets/demo/server.py).
160+
As an example, see [`server.py` of the demo](https://github.com/bcdev/chartlets/tree/main/chartlets.py/chartlets/demo/server.py).
57161

58-
### 5. Consume the extensions
162+
### Consume the extensions
59163

60164
Use JavaScript package `chartlets` in your frontend to implement the
61165
contribution lifecycle in your React application.
62166

63-
As an example, see [the demo application](chartlets.js/src/demo).
167+
As an example, see [the demo application](https://github.com/bcdev/chartlets/tree/main/chartlets.js/src/demo).

0 commit comments

Comments
 (0)