-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
275 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
## Download | ||
|
||
::: code-group | ||
<<< @/../../examples/core_features/download_txt.py | ||
<<< @/../../examples/core_features/download_binary.py | ||
::: | ||
|
||
## Upload | ||
|
||
<<< @/../../examples/core_features/upload.py | ||
|
||
## Browse | ||
|
||
<<< @/../../examples/core_features/sys_filebrowser.py | ||
<<< @/../../examples/core_features/sys_filebrowser.py | ||
|
||
## Local CSS file | ||
|
||
::: code-group | ||
<<< @/../../examples/core_features/custom_css.py | ||
<<< @/../../examples/core_features/custom.css | ||
::: | ||
|
||
## Local images as URL | ||
|
||
::: code-group | ||
<<< @/../../examples/core_features/images_inline.py | ||
<<< @/../../examples/core_features/images_http.py | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,29 @@ | ||
## Exposing a trame application into Jupyter | ||
# Exposing a trame application into Jupyter | ||
|
||
## Disable warning | ||
|
||
```python | ||
import os | ||
os.environ["TRAME_DISABLE_V3_WARNING"] = "1" | ||
``` | ||
|
||
## Define application | ||
|
||
<<< @/../../examples/core_features/jupyter.py | ||
|
||
## Use application within Jupyter | ||
|
||
```python | ||
cone = Cone() | ||
await cone.ui.ready | ||
cone.ui | ||
``` | ||
|
||
![Trame in Jupyer](/assets/images/deployment/jupyter.png) | ||
|
||
## Edit state in another cell | ||
|
||
```python | ||
cone.resolution = 4 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## Widgets compatibility and package name | ||
|
||
| Widget name (trame.widget.{name}) | Package name | Supported version | Number of components | | ||
| --- | --- | --- | --- | | ||
| html | (built-in) | 2 & 3 | 80 | | ||
| client | (built-in) | 2 & 3 | 5 | | ||
| vuetify, vuetify2, vuetify3 | trame-vuetify | 2 & 3 | 146/156 | | ||
| router | trame-router | 2 & 3 | 2 | | ||
| vtk, paraview | trame-vtk | 2 & 3 | 15 | | ||
| plotly | trame-plotly | 2 & 3 | 1 | | ||
| xterm | trame-xterm | 2 & 3 | 1 | | ||
| code | trame-code | 2 & 3 | 1 | | ||
| iframe | trame-iframe | 2 & 3 | 2 | | ||
| trame | trame-components | 2 & 3 | 11 | | ||
| keycloak | trame-keycloak | 2 & 3 (wip) | 1 | | ||
| quasar | trame-quasar | 3 | 123 | | ||
| formkit | trame-formkit | 3 | 2 | | ||
| leaflet | trame-leaflet | 2 | 22 | | ||
| pvui | trame-pvui | 2 | . | | ||
| grid | trame-grid-layout | 2 | 2 | | ||
| tauri | trame-tauri | 2 | - | | ||
| vega | trame-vega | 2 | 1 | | ||
| simput | trame-simput | 2 | 2 | | ||
| rca | trame-rca | 2 (wip for 3) | 7 | | ||
| matplotlib | trame-matplotlib | 2 | 1 | | ||
| markdown | trame-markdown | 2 | 1 | | ||
| deckgl | trame-deckgl | 2 | 1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from trame.app import get_server | ||
from trame.decorators import TrameApp, change, controller, trigger, life_cycle | ||
from trame.ui.html import DivLayout | ||
from trame.widgets import html | ||
|
||
|
||
@TrameApp() | ||
class App: | ||
def __init__(self, name=None): | ||
self.server = get_server(name) | ||
self.ui() | ||
|
||
@property | ||
def state(self): | ||
return self.server.state | ||
|
||
@property | ||
def ctrl(self): | ||
return self.server.controller | ||
|
||
@trigger("exec") | ||
def method_call(self, msg): | ||
print("method_called", msg) | ||
|
||
@controller.set("hello") | ||
def method_on_ctrl(self, *args): | ||
print("method_on_ctrl", args) | ||
|
||
@change("resolution") | ||
def one_slider(self, resolution, **kwargs): | ||
print("Slider value 1", resolution) | ||
|
||
@life_cycle.server_ready | ||
def on_ready(self, *args, **kwargs): | ||
print("on_ready") | ||
|
||
def ui(self): | ||
with DivLayout(self.server) as layout: | ||
html.Input( | ||
type="range", | ||
min=3, | ||
max=60, | ||
step=1, | ||
v_model_number=("resolution", 6), | ||
) | ||
html.Button("trigger", click="trigger('exec', ['trigger'])") | ||
html.Button("method", click=(self.method_call, "['method']")) | ||
html.Button("ctrl", click=self.ctrl.hello) | ||
|
||
|
||
if __name__ == "__main__": | ||
app = App() | ||
app.server.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
background-color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from pathlib import Path | ||
|
||
from trame.app import get_server | ||
from trame.widgets import client | ||
from trame.ui.html import DivLayout | ||
|
||
CSS_FILE = Path(__file__).with_name("custom.css") | ||
|
||
server = get_server() | ||
with DivLayout(server): | ||
client.Style(CSS_FILE.read_text()) | ||
|
||
|
||
if __name__ == "__main__": | ||
server.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from pathlib import Path | ||
from trame.app import get_server | ||
from trame.ui.html import DivLayout | ||
from trame.widgets import html | ||
|
||
BINARY_FILE = Path(__file__).parent.parent / "data/can.ex2" | ||
|
||
server = get_server() | ||
state, ctrl = server.state, server.controller | ||
|
||
|
||
@ctrl.trigger("download_binary") | ||
def download(): | ||
return server.protocol.addAttachment(BINARY_FILE.read_bytes()) | ||
|
||
|
||
with DivLayout(server): | ||
html.Button( | ||
"Download ", | ||
click="utils.download('can.ex2', trigger('download_binary'), 'application/octet-stream')", | ||
) | ||
|
||
if __name__ == "__main__": | ||
server.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import time | ||
from trame.app import get_server | ||
from trame.ui.html import DivLayout | ||
from trame.widgets import html | ||
|
||
server = get_server() | ||
state, ctrl = server.state, server.controller | ||
|
||
state.other_txt_content = "Some content to download..." | ||
|
||
|
||
@ctrl.trigger("download_content") | ||
def generate_content(): | ||
return f"Hello on the server is {time.time()}" | ||
|
||
|
||
with DivLayout(server): | ||
html.Button( | ||
"Download from method", | ||
click="utils.download('method.txt', trigger('download_content'), 'text/plain')", | ||
) | ||
html.Button( | ||
"Download from state", | ||
click="utils.download('state.txt', other_txt_content, 'text/plain')", | ||
) | ||
|
||
if __name__ == "__main__": | ||
server.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from pathlib import Path | ||
|
||
from trame.app import get_server | ||
from trame.widgets import html | ||
from trame.ui.html import DivLayout | ||
|
||
|
||
DIRECTORY = Path(__file__).parent.parent.parent / "docs/vitepress/assets/images/apps" | ||
|
||
server = get_server() | ||
server.enable_module({"serve": {"data": str(DIRECTORY.absolute())}}) | ||
|
||
with DivLayout(server): | ||
for file in DIRECTORY.iterdir(): | ||
html.Img(src=f"/data/{file.name}", style="width: 200px;") | ||
|
||
|
||
if __name__ == "__main__": | ||
server.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from pathlib import Path | ||
|
||
from trame.app import get_server | ||
from trame.assets.local import LocalFileManager | ||
from trame.widgets import html | ||
from trame.ui.html import DivLayout | ||
|
||
|
||
KEYS = [] | ||
DIRECTORY = Path(__file__).parent.parent.parent / "docs/vitepress/assets/images/apps" | ||
ASSETS = LocalFileManager(DIRECTORY) | ||
|
||
for image in DIRECTORY.iterdir(): | ||
key = image.stem.replace("-", "_") | ||
ASSETS.url(key, image.name) | ||
KEYS.append(key) | ||
|
||
|
||
server = get_server() | ||
with DivLayout(server): | ||
for key in KEYS: | ||
html.Img(src=ASSETS[key], style="width: 200px;") | ||
|
||
|
||
if __name__ == "__main__": | ||
server.start() |
Oops, something went wrong.