Skip to content

Commit d253af6

Browse files
authored
Merge pull request #216 from plotly/improve-README
A few improvements to the repo README
2 parents 28f6af9 + e551885 commit d253af6

File tree

1 file changed

+112
-93
lines changed

1 file changed

+112
-93
lines changed

README.md

Lines changed: 112 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
# Dash for Julia
22

3-
[![Juila tests](https://github.com/plotly/Dash.jl/actions/workflows/jl_test.yml/badge.svg)](https://github.com/plotly/Dash.jl/actions/workflows/jl_test.yml)
4-
[![CircleCI](https://circleci.com/gh/plotly/Dash.jl/tree/master.svg?style=svg)](https://circleci.com/gh/plotly/Dash.jl/tree/master)
5-
[![GitHub](https://img.shields.io/github/license/plotly/dashR.svg?color=dark-green)](https://github.com/plotly/Dash.jl/blob/master/LICENSE)
3+
[![Juila tests](https://github.com/plotly/Dash.jl/actions/workflows/jl_test.yml/badge.svg?query=branch%3Adev)](https://github.com/plotly/Dash.jl/actions/workflows/jl_test.yml?query=branch%3Adev)
4+
[![CircleCI](https://img.shields.io/circleci/build/github/plotly/Dash.jl/dev.svg)](https://circleci.com/gh/plotly/Dash.jl/tree/dev)
5+
[![GitHub](https://img.shields.io/github/license/plotly/Dash.jl.svg?color=dark-green)](https://github.com/plotly/Dash.jl/blob/master/LICENSE)
66
[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/plotly/Dash.jl.svg?color=dark-green)](https://github.com/plotly/Dash.jl/graphs/contributors)
77

8-
## Project Status
8+
#### Create beautiful, analytic applications in Julia
99

10-
As of [v1.15.0](https://github.com/plotly/dash/releases/tag/v1.15.0) of Dash, Julia components can be generated in tandem with Python and R components. Interested in getting involved with the project? Sponsorship is a great way to accelerate the progress of open source projects like this one; please feel free to [reach out to us](https://plotly.com/consulting-and-oem/)!
10+
Built on top of Plotly.js, React and HTTP.jl, [Dash](https://plotly.com/dash/) ties modern UI elements like dropdowns, sliders, and graphs directly to your analytical Julia code.
1111

1212
Just getting started? Check out the [Dash for Julia User Guide](https://dash.plotly.com/julia)! If you can't find documentation there, then check out the unofficial [contributed examples](https://github.com/plotly/Dash.jl/issues/50) or check out source code from [demo applications](https://dash.gallery) in Python and then reference the Julia syntax style.
1313

14-
#### Create beautiful, analytic applications in Julia
14+
## Project Status
1515

16-
Built on top of Plotly.js, React and HTTP.jl, [Dash](https://plotly.com/dash/) ties modern UI elements like dropdowns, sliders, and graphs directly to your analytical Julia code.
16+
Julia components can be generated in tandem with Python and R components. Interested in getting involved with the project? Sponsorship is a great way to accelerate the progress of open source projects like this one; please feel free to [reach out to us](https://plotly.com/consulting-and-oem/)!
1717

1818
## Installation
1919

20-
Please ensure that you are using a version of Julia >= 1.2.
21-
2220
To install the most recently released version:
2321

2422
```julia
@@ -35,151 +33,172 @@ pkg> add Dash#dev
3533

3634
### Basic application
3735

38-
```jldoctest
39-
julia> using Dash
40-
41-
julia> app = dash(external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"])
42-
43-
julia> app.layout = html_div() do
44-
html_h1("Hello Dash"),
45-
html_div("Dash.jl: Julia interface for Dash"),
46-
dcc_graph(
47-
id = "example-graph",
48-
figure = (
49-
data = [
50-
(x = [1, 2, 3], y = [4, 1, 2], type = "bar", name = "SF"),
51-
(x = [1, 2, 3], y = [2, 4, 5], type = "bar", name = "Montréal"),
52-
],
53-
layout = (title = "Dash Data Visualization",)
54-
)
55-
)
56-
end
36+
```julia
37+
using Dash
5738

58-
julia> run_server(app, "0.0.0.0", 8080)
59-
```
39+
app = dash(external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"])
40+
41+
app.layout = html_div() do
42+
html_h1("Hello Dash"),
43+
html_div("Dash.jl: Julia interface for Dash"),
44+
dcc_graph(id = "example-graph",
45+
figure = (
46+
data = [
47+
(x = [1, 2, 3], y = [4, 1, 2], type = "bar", name = "SF"),
48+
(x = [1, 2, 3], y = [2, 4, 5], type = "bar", name = "Montréal"),
49+
],
50+
layout = (title = "Dash Data Visualization",)
51+
))
52+
end
6053

61-
* The `DashApp` struct represents a dashboard application.
62-
* 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
63-
* Unlike the Python version where each Dash component is represented as a separate class, all components in Dash.jl are represented by struct `Component`.
64-
* 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 Dash.jl it is created using function `html_div`
65-
* The list of all supported components is available in docstring for Dash.jl module.
66-
* 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.
67-
* 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.
68-
* ``make_handler(app::Dash; debug::Bool = false)`` makes a handler function for using in HTTP package.
54+
run_server(app)
55+
```
6956

70-
__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!__
57+
__then go to `http://127.0.0.1:8050` in your browser to view the Dash app!__
7158

7259
### Basic Callback
7360

74-
```jldoctest
75-
76-
julia> using Dash
61+
```julia
62+
using Dash
7763

78-
julia> app = dash(external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"])
64+
app = dash(external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"])
7965

80-
julia> app.layout = html_div() do
81-
dcc_input(id = "my-id", value="initial value", type = "text"),
82-
html_div(id = "my-div")
83-
end
66+
app.layout = html_div() do
67+
dcc_input(id = "my-id", value = "initial value", type = "text"),
68+
html_div(id = "my-div")
69+
end
8470

85-
julia> callback!(app, Output("my-div", "children"), Input("my-id", "value")) do input_value
71+
callback!(app, Output("my-div", "children"), Input("my-id", "value")) do input_value
8672
"You've entered $(input_value)"
8773
end
8874

89-
julia> run_server(app, "0.0.0.0", 8080)
75+
run_server(app)
9076
```
9177

92-
* You can make your dashboard interactive by register callbacks for changes in frontend with function ``callback!(func::Function, app::Dash, output, input, state)``
93-
* Inputs and outputs (and states, see below) of callback can be `Input`, `Output`, `State` objects or vectors of this objects
94-
* Callback function must have the signature(inputs..., states...), and provide a return value comparable (in terms of number of elements) to the outputs being updated.
78+
* You can make your Dash app interactive by registering callbacks with the `callback!` function.
79+
* Outputs and inputs (and states, see below) of callback can be `Output`, `Input`, `State` objects or splats / vectors of this objects.
80+
* Callback functions must have the signature ``(inputs..., states...)``, and provide a return value with the same number elements as the number of `Output`s to update.
9581

9682
### States and Multiple Outputs
9783

98-
```jldoctest
99-
julia> using Dash
84+
```julia
85+
using Dash
10086

101-
julia> app = dash(external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"])
87+
app = dash(external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"])
10288

103-
julia> app.layout = html_div() do
104-
dcc_input(id = "my-id", value="initial value", type = "text"),
105-
html_div(id = "my-div"),
106-
html_div(id = "my-div2")
107-
end
89+
app.layout = html_div() do
90+
dcc_input(id = "my-id", value = "initial value", type = "text"),
91+
html_div(id = "my-div"),
92+
html_div(id = "my-div2")
93+
end
10894

109-
julia> callback!(app, [Output("my-div","children"), Output("my-div2","children")], Input("my-id", "value"), State("my-id", "type")) do input_value, state_value
110-
"You've entered $(input_value) in input with type $(state_value)",
111-
"You've entered $(input_value)"
95+
callback!(app,
96+
Output("my-div","children"),
97+
Output("my-div2","children"),
98+
Input("my-id", "value"),
99+
State("my-id", "type")) do input_value, state_value
100+
return ("You've entered $(input_value) in input with type $(state_value)",
101+
"You've entered $(input_value)")
112102
end
113-
julia> run_server(app, "0.0.0.0", 8080)
103+
104+
run_server(app)
114105
```
115106

116107
## Comparison with original Python syntax
117108

118-
### component naming:
109+
### Component naming
110+
111+
* Python:
112+
113+
```python
114+
import dash
115+
116+
dash.html.Div
117+
dash.dcc.Graph
118+
dash.dash_table.DataTable
119+
```
120+
121+
* Dash.jl:
122+
123+
```julia
124+
using Dash
125+
126+
html_div
127+
dcc_graph
128+
dash_datatable
129+
```
130+
131+
### Component creation
132+
133+
Just as in Python, functions for declaring components have keyword arguments, which are the same as in Python. ``html_div(id = "my-id", children = "Simple text")``.
119134

120-
`html.Div` => `html_div`, `dcc.Graph` => `dcc_graph` and etc
135+
For components which declare `children`, two additional signatures are available:
121136

122-
### component creation:
137+
* ``(children; kwargs..)`` and
138+
* ``(children_maker::Function; kwargs...)``
123139

124-
Just as in Python, functions for declaring components have keyword arguments, which are the same as in Python. ``html_div(id="my-id", children="Simple text")``.
125-
For components which declare `children`, two additional signatures are available. ``(children; kwargs..)`` and ``(children_maker::Function; kwargs...)`` so one can write ``html_div("Simple text", id="my-id")`` for simple elements, or choose an abbreviated syntax with `do` syntax for complex elements:
140+
So one can write ``html_div("Simple text", id = "my-id")`` for simple elements, or choose an abbreviated syntax with `do` syntax for complex elements:
126141

127142
```julia
128-
html_div(id="outer-div") do
143+
html_div(id = "outer-div") do
129144
html_h1("Welcome"),
130-
html_div(id="inner-div") do
131-
......
145+
html_div(id = "inner-div") do
146+
#= inner content =#
132147
end
133148
end
134149
```
135150

136-
### application and layout:
151+
### Application and layout
137152

138-
* python:
153+
* Python:
139154

140155
```python
141-
app = dash.Dash("Test", external_stylesheets=external_stylesheets)
156+
app = dash.Dash(external_stylesheets=["https://codepen.io/chriddyp/pen/bWLwgP.css"])
157+
142158
app.layout = html.Div(children=[....])
143159
```
144160

145161
* Dash.jl:
146162

147163
```julia
148-
app = dash("Test", external_stylesheets=external_stylesheets)
164+
app = dash(external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"])
149165

150166
app.layout = html_div() do
151-
......
152-
end
167+
#= inner content =#
168+
end
153169
```
154170

155-
### callbacks:
171+
### Callbacks
156172

157173
* Python:
158174

159175
```python
160176
@app.callback(Output('output', 'children'),
161-
[Input('submit-button', 'n_clicks')],
162-
[State('state-1', 'value'),
163-
State('state-2', 'value')])
177+
Input('submit-button', 'n_clicks')],
178+
State('state-1', 'value'),
179+
State('state-2', 'value'))
164180
def update_output(n_clicks, state1, state2):
165-
.....
166-
181+
# logic
167182
```
168183

169184
* Dash.jl:
170185

171186
```julia
172-
callback!(app, Output("output", "children"),
173-
[Input("submit-button", "n_clicks")],
174-
[State("state-1", "value"),
175-
State("state-2", "value")]) do n_clicks, state1, state2
176-
.....
187+
callback!(app,
188+
Output("output", "children"),
189+
Input("submit-button", "n_clicks")],
190+
State("state-1", "value"),
191+
State("state-2", "value")) do n_clicks, state1, state2
192+
# logic
177193
end
178194
```
179195

180-
Be careful - in Dash.jl states come first in an arguments list.
196+
### JSON
197+
198+
Dash apps transfer data between the browser (aka the frontend) and the Julia process running the app (aka the backend) in JSON.
199+
Dash.jl uses [JSON3.jl](https://github.com/quinnj/JSON3.jl) for JSON serialization/deserialization.
181200

182-
### JSON:
201+
Note that JSON3.jl converts
183202

184-
I use JSON3.jl for JSON serialization/deserialization.
185-
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",)`
203+
* `Vector`s and `Tuple`s to JSON arrays
204+
* `Dict`s and `NamedTuple`s to JSON objects

0 commit comments

Comments
 (0)