excalidraw interactive drawing and freeform component for dash.
Project description
Dash Excalidraw
A Dash component that wraps the powerful Excalidraw drawing and diagramming tool, providing a customizable canvas for creating beautiful hand-drawn like diagrams, wireframes, and sketches directly in your Dash applications.
Docs
https://pip-install-python.com/pip/dash_excalidraw
Full Tutorial Video on YouTube
Features
The Dash Excalidraw component inherits all the powerful features of the Excalidraw editor:
- Free & open-source
- Infinite, canvas-based whiteboard
- Hand-drawn like style
- Dark mode support
- Highly customizable
- Image support
- Shape libraries support
- Localization (i18n) support
- Export to PNG, SVG & clipboard
- Open format - export drawings as
.excalidrawJSON file - Rich toolset - rectangle, circle, diamond, arrow, line, free-draw, eraser & more
- Arrow-binding & labeled arrows
- Undo / Redo support
- Zoom and panning support
- And many more...
Installation
pip install dash-excalidraw==0.0.4
Quick Start
Here's a simple example to get you started:
import dash_excalidraw
from dash import Dash, html
import dash_mantine_components as dmc
app = Dash(__name__)
app.layout = dmc.MantineProvider([
dmc.Container([
dmc.Title("Dash Excalidraw Demo", order=1),
dash_excalidraw.DashExcalidraw(
id='excalidraw',
width='100%',
height='600px',
initialData={"elements": [], "appState": {}},
theme="light"
)
])
])
if __name__ == '__main__':
app.run_server(debug=True)
Props & Options
| Option | Default | Type | Description |
|---|---|---|---|
id |
None |
string | The ID used to identify this component in Dash callbacks |
width |
'100%' |
string | The width of the Excalidraw component |
height |
'400px' |
string | The height of the Excalidraw component |
initialData |
{ elements: [], appState: {} } |
object | Initial data to load into the component |
theme |
'light' |
'light' | 'dark' |
The theme of the component |
viewModeEnabled |
false |
boolean | Enables view-only mode |
zenModeEnabled |
false |
boolean | Enables zen mode |
gridModeEnabled |
false |
boolean | Enables grid mode |
isCollaborating |
false |
boolean | Indicates if the component is in collaboration mode |
Callback Example
from dash import callback, Input, Output
import json
@callback(
Output('output', 'children'),
Input('excalidraw', 'serializedData'),
)
def display_output(serializedData):
if not serializedData:
return 'No elements drawn yet'
data = json.loads(serializedData)
return f'Number of elements: {len(data["elements"])}'
Props Documentation
Core Props
Click to expand
| Prop | Type | Default | Description |
|---|---|---|---|
id |
string | None | Component identifier |
width |
string | '100%' | Component width |
height |
string | '400px' | Component height |
initialData |
object | { elements: [], appState: {} } |
Initial scene data |
elements |
array | [] |
Current scene elements |
appState |
object | {} |
Application state |
files |
object | {} |
Associated files |
serializedData |
string | '' |
Serialized scene data |
Interactive Features
Click to expand
| Prop | Type | Default | Description |
|---|---|---|---|
excalidrawAPI |
function | null | Access Excalidraw API |
onPointerUpdate |
function | null | Pointer update callback |
onPointerDown |
function | null | Pointer down callback |
onScrollChange |
function | null | Scroll change callback |
onPaste |
function | null | Paste event callback |
onLibraryChange |
function | null | Library change callback |
onLinkOpen |
function | null | Link open callback |
UI Customization
Click to expand
| Prop | Type | Default | Description |
|---|---|---|---|
theme |
string | 'light' | UI theme |
langCode |
string | 'en' | Localization code |
renderTopRightUI |
function | null | Custom top-right UI |
renderCustomStats |
function | null | Custom stats display |
UIOptions |
object | {} |
UI customization options |
Advanced Example
import dash_excalidraw
from dash import Dash, html, callback, Input, Output
import dash_mantine_components as dmc
import json
app = Dash(__name__)
app.layout = dmc.MantineProvider([
dmc.Container([
dmc.Title("Dash Excalidraw Demo", order=1, align="center", mb="lg"),
dash_excalidraw.DashExcalidraw(
id='excalidraw',
width='100%',
height='600px',
initialData={
"elements": [],
"appState": {
"viewBackgroundColor": "#ffffff",
"gridSize": 20
}
},
theme="light",
viewModeEnabled=False,
zenModeEnabled=False,
gridModeEnabled=True
),
html.Div(id='output')
], size="xl", pt="md")
], withGlobalStyles=True)
@callback(
Output('output', 'children'),
Input('excalidraw', 'serializedData')
)
def display_output(serializedData):
if not serializedData:
return 'No elements drawn yet'
data = json.loads(serializedData)
return f'Number of elements: {len(data["elements"])}'
if __name__ == '__main__':
app.run_server(debug=True)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built on top of the amazing Excalidraw library
- Developed for use with Plotly Dash
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dash_excalidraw-0.0.4.tar.gz.
File metadata
- Download URL: dash_excalidraw-0.0.4.tar.gz
- Upload date:
- Size: 1.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
495ae3a0e3dec76a20238288ee417480210602ee6d614e2df39b048af22deab9
|
|
| MD5 |
257d7ccb4acdd4922a4c4a515a12072c
|
|
| BLAKE2b-256 |
a8ce198653365490f89f548798c347f8f8c4fea981957f23103c9502b98f070f
|
File details
Details for the file dash_excalidraw-0.0.4-py3-none-any.whl.
File metadata
- Download URL: dash_excalidraw-0.0.4-py3-none-any.whl
- Upload date:
- Size: 1.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46419b0a3f67b116443cb66f7f4db01ea52ea9df49e04b5bad8fe7f3a4d6ea37
|
|
| MD5 |
6e87f8ab39675e3faf80f3d041001b4f
|
|
| BLAKE2b-256 |
1e5e19de913a08b2b36b02dd0a5a7fa13ddc3f36d5ac716b8778efbfb423c4c2
|