Skip to content

Commit b302856

Browse files
authored
Merge pull request #40 from PallHaraldsson/patch-1
Fixed examples
2 parents 9d2d74f + b8249e2 commit b302856

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

README.md

+26-14
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Pkg.add(PackageSpec(url="https://github.com/plotly/dash-table.git", rev="jl"))
3232

3333
```jldoctest
3434
julia> using Dash
35+
julia> using DashHtmlComponents
36+
julia> using DashCoreComponents
37+
3538
julia> app = dash(external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"])
3639
3740
julia> app.layout = html_div() do
@@ -48,16 +51,18 @@ julia> app.layout = html_div() do
4851
)
4952
)
5053
end
54+
5155
julia> run_server(app, "0.0.0.0", 8080)
5256
```
53-
* The `DashApp` struct represent dashboard application.
57+
58+
* The `DashApp` struct represents a dashboard application.
5459
* To make `DashApp` struct use `dash(layout_maker::Function, name::String; external_stylesheets::Vector{String} = Vector{String}(), url_base_pathname="/", assets_folder::String = "assets")`` where `layout_maker` is a function with signature ()::Component
55-
* Unlike the python version where each Dash component is represented as a separate class, all components in Dash.jl are represented by struct `Component`.
56-
* You can create `Component` specific for concrete Dash component by the set of functions in the form ``lowercase(<component package>)_lowercase(<component name>)``. For example, in python html `<div>` element is represented as `HTML.Div` in Dasboards it is created using function `html_div`
57-
* The list of all supported components is available in docstring for Dasboards module
58-
* All functions for a component creation have the signature `(;kwargs...)::Component`. List of key arguments specific for the concrete component is available in the docstring for each function
59-
* Functions for creation components which have `children` property have two additional methods ``(children::Any; kwargs...)::Component`` and ``(children_maker::Function; kwargs..)::Component``. `children` must by string or number or single component or collection of components
60-
* ``make_handler(app::Dash; debug::Bool = false)`` makes handler function for using in HTTP package
60+
* Unlike the Python version where each Dash component is represented as a separate class, all components in Dash.jl are represented by struct `Component`.
61+
* You can create `Component` specific for concrete Dash component by the set of functions in the form ``lowercase(<component package>)_lowercase(<component name>)``. For example, in Python html `<div>` element is represented as `HTML.Div` in Dasboards it is created using function `html_div`
62+
* The list of all supported components is available in docstring for Dasboards module.
63+
* All functions for a component creation have the signature `(;kwargs...)::Component`. List of key arguments specific for the concrete component is available in the docstring for each function.
64+
* Functions for creation components which have `children` property have two additional methods ``(children::Any; kwargs...)::Component`` and ``(children_maker::Function; kwargs..)::Component``. `children` must by string or number or single component or collection of components.
65+
* ``make_handler(app::Dash; debug::Bool = false)`` makes a handler function for using in HTTP package.
6166

6267

6368
__Once you have run the code to create the Dashboard, go to `http://127.0.0.1:8080` in your browser to view the Dashboard!__
@@ -66,6 +71,9 @@ __Once you have run the code to create the Dashboard, go to `http://127.0.0.1:80
6671
```jldoctest
6772
6873
julia> using Dash
74+
julia> using DashHtmlComponents
75+
julia> using DashCoreComponents
76+
6977
julia> app = dash(external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"])
7078
7179
julia> app.layout = html_div() do
@@ -76,17 +84,21 @@ julia> app.layout = html_div() do
7684
julia> callback!(app, callid"my-id.value => my-div.children") do input_value
7785
"You've entered $(input_value)"
7886
end
79-
julia> run_server(app, "0.0.0.0", 8080)
8087
88+
julia> run_server(app, "0.0.0.0", 8080)
8189
```
90+
8291
* You can make your dashboard interactive by register callbacks for changes in frontend with function ``callback!(func::Function, app::Dash, id::CallbackId)``
8392
* Inputs and outputs (and states, see below) of callback are described by struct `CallbackId` which can easily created by string macro `callid""`
8493
* `callid""` parse string in form ``"[{state1 [,...]}] input1[,...] => output1[,...]"`` where all items is ``"<element id>.<property name>"``
85-
* Callback function must have the signature(states..., inputs...), and provide a return value comparable (in terms of number of elements) to the outputs being updated.
94+
* Callback functions must have the signature(states..., inputs...), and provide a return value comparable (in terms of number of elements) to the outputs being updated.
8695

8796
### States and Multiple Outputs
8897
```jldoctest
8998
julia> using Dash
99+
julia> using DashHtmlComponents
100+
julia> using DashCoreComponents
101+
90102
julia> app = dash(external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"])
91103
92104
julia> app.layout = html_div() do
@@ -102,7 +114,7 @@ end
102114
julia> run_server(app, "0.0.0.0", 8080)
103115
```
104116

105-
## Comparation with original python syntax
117+
## Comparation with original Python syntax
106118

107119
### component naming:
108120

@@ -139,7 +151,7 @@ app.layout = html_div() do
139151

140152
```
141153
### callbacks:
142-
* python:
154+
* Python:
143155
```python
144156
@app.callback(Output('output', 'children'),
145157
[Input('submit-button', 'n_clicks')],
@@ -157,9 +169,9 @@ callback!(app, callid"""{state1.value, state2.value}
157169
.....
158170
end
159171
```
160-
Be careful - in Dash.jl states came first in arguments list
172+
Be careful - in Dash.jl states come first in an arguments list.
161173

162-
### json:
163-
I use JSON2 for json serialization/deserialization, so in callbacks all JSON objects are `NamedTuples` rather than dictionaries. Within component properties you can use both `Dict` and `NamedTuple` for json objects.
174+
### JSON:
175+
I use JSON2.jl for JSON serialization/deserialization, so in callbacks all JSON objects are `NamedTuples` rather than dictionaries. Within component properties you can use both `Dict` and `NamedTuple` for JSON objects.
164176

165177
Note when declaring elements with a single properly that `layout = (title = "Test graph")` is not interpreted as a `NamedTuple` by Julia - you'll need to add a comma when declaring the layout, e.g. `layout = (title = "Test graph",)`

src/Dash.jl

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Julia backend for [Plotly Dash](https://github.com/plotly/dash)
3131
```julia
3232
3333
using Dash
34+
using DashHtmlComponents
35+
using DashCoreComponents
3436
app = dash(external_stylesheets=["https://codepen.io/chriddyp/pen/bWLwgP.css"]) do
3537
html_div() do
3638
dcc_input(id="graphTitle", value="Let's Dance!", type = "text"),

0 commit comments

Comments
 (0)