Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ version = "0.1.0"

[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
DashBase = "03207cf0-e2b3-4b91-9ca8-690cf0fb507e"
DashCoreComponents = "1b08a953-4be3-4667-9a23-9da06441d987"
DashHtmlComponents = "1b08a953-4be3-4667-9a23-24100242a84a"
DashTable = "1b08a953-4be3-4667-9a23-f0e2ba4deb9a"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
MD5 = "6ac74813-4b46-53a4-afec-0b5dc9d7885c"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
Expand All @@ -18,6 +21,11 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
CodecZlib = "0.7.0"
DashBase = "0.1.0"
DashCoreComponents = "1.10.2"
DashHtmlComponents = "1.0.3"
DashTable = "4.9.0"
DataStructures = "0.17.5"
HTTP = "0.8.10"
JSON = "0.21.0"
Expand All @@ -30,4 +38,4 @@ julia = "1.1"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Test"]
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ To install the latest (stable) development version instead:

```julia
using Pkg
Pkg.add(PackageSpec(url="https://github.com/plotly/Dash.jl.git", rev="dev"))
Pkg.add(PackageSpec(url="https://github.com/plotly/DashBase.jl.git"))
Comment thread
alexcjohnson marked this conversation as resolved.
Pkg.add(PackageSpec(url="https://github.com/plotly/dash-html-components.git", rev="master"))
Pkg.add(PackageSpec(url="https://github.com/plotly/dash-core-components.git", rev="master"))
Pkg.add(PackageSpec(url="https://github.com/plotly/dash-table.git", rev="master"))
Pkg.add(PackageSpec(url="https://github.com/plotly/Dash.jl.git", rev="dev"))
```

## Usage
Expand Down
48 changes: 4 additions & 44 deletions src/Components.jl
Original file line number Diff line number Diff line change
@@ -1,41 +1,3 @@
module Components
import JSON2
export Component, <|, hasproperty, is_prop_available, validate

abstract type AbstractComponent end


struct Component <: AbstractComponent
type ::String
namespace ::String
props ::Dict{Symbol, Any}
available_props ::Set{Symbol}
wildcard_props ::Set{Symbol}
end

JSON2.@format Component begin
available_props => (exclude = true,)
wildcard_props => (exclude = true,)
end

function <|(comp::Component, value::Any)
comp.props["children"] = value
return comp
end

hasproperty(c::Component, prop::Symbol) = haskey(c.props, prop)
function is_prop_available(c::Component, prop::Symbol)
if length(c.wildcard_props) > 0
wild_regs = Regex("^(?<prop>$(join(c.wildcard_props, "|")))")
if !isnothing(match(wild_regs, string(prop)))
return true
end
end

return prop in c.available_props
end


function _validate_children(children::Union{Vector, Tuple}, ids::Set{Symbol})
for child in children
_validate(child, ids)
Expand All @@ -48,17 +10,15 @@ function _validate_children(children, ids::Set{Symbol}) end


function _validate(comp::Component, ids::Set{Symbol})
if haskey(comp.props, :id)
id = Symbol(comp.props[:id])
if hasproperty(comp, :id) && !isnothing(comp.id)
id = Symbol(comp.id)
id in ids && error("Duplicate component id found in the initial layout: $(id)")
push!(ids, id)
end
_validate_children(get(comp.props, :children, nothing), ids)
hasproperty(comp, :children) && _validate_children(comp.children, ids)
end
function _validate(non_comp, ids::Set{Symbol}) end

function validate(comp::Component)
_validate(comp, Set{Symbol}())
end

end
end
80 changes: 74 additions & 6 deletions src/Dash.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
module Dash
using DashBase
import HTTP, JSON2, CodecZlib, MD5
using Sockets
const ROOT_PATH = realpath(joinpath(@__DIR__, ".."))
const RESOURCE_PATH = realpath(joinpath(ROOT_PATH, "resources"))
include("exceptions.jl")
include("Components.jl")
include("Front.jl")
include("HttpHelpers/HttpHelpers.jl")
import .Front
using .Components

using .HttpHelpers

export dash, Component, Front, callback!,
Expand All @@ -20,7 +21,6 @@ include("Contexts/Contexts.jl")
include("env.jl")
include("utils.jl")
include("app.jl")
include("resources/registry.jl")
include("resources/application.jl")
include("handlers.jl")
include("server.jl")
Expand All @@ -39,14 +39,14 @@ using DashCoreComponents
app = dash(external_stylesheets=["https://codepen.io/chriddyp/pen/bWLwgP.css"]) do
html_div() do
dcc_input(id="graphTitle", value="Let's Dance!", type = "text"),
html_div(id="outputID"),
html_div(id="outputID"),
dcc_graph(id="graph",
figure = (
data = [(x = [1,2,3], y = [3,2,8], type="bar")],
layout = Dict(:title => "Graph")
)
)

end
end
callback!(app, Output("outputID", "children"), Input("graphTitle","value"), State("graphTitle","type")) do value, type
Expand All @@ -56,7 +56,7 @@ callback!(app, Output("graph", "figure"), Input("graphTitle", "value")) do value
(
data = [
(x = [1,2,3], y = abs.(randn(3)), type="bar"),
(x = [1,2,3], y = abs.(randn(3)), type="scatter", mode = "lines+markers", line = (width = 4,))
(x = [1,2,3], y = abs.(randn(3)), type="scatter", mode = "lines+markers", line = (width = 4,))
],
layout = (title = value,)
)
Expand All @@ -67,5 +67,73 @@ run_server(app, HTTP.Sockets.localhost, 8050)
""" Dash


function __init__()
DashBase.main_registry().dash_dependency = (
dev = ResourcePkg(
"dash_renderer",
RESOURCE_PATH, version = "1.5.0",
[
Resource(
relative_package_path = "react@16.13.0.js",
external_url = "https://unpkg.com/react@16.13.0/umd/react.development.js"
),
Resource(
relative_package_path = "react-dom@16.13.0.js",
external_url = "https://unpkg.com/react-dom@16.13.0/umd/react-dom.development.js"
),
Resource(
relative_package_path = "polyfill@7.8.7.min.js",
external_url = "https://unpkg.com/@babel/polyfill@7.8.7/dist/polyfill.min.js"
),
Resource(
relative_package_path = "prop-types@15.7.2.js",
external_url = "https://unpkg.com/prop-types@15.7.2/prop-types.js",
),
]
),
prod = ResourcePkg(
"dash_renderer",
RESOURCE_PATH, version = "1.2.2",
[
Resource(
relative_package_path = "react@16.13.0.min.js",
external_url = "https://unpkg.com/react@16.13.0/umd/react.production.min.js"
),
Resource(
relative_package_path = "react-dom@16.13.0.min.js",
external_url = "https://unpkg.com/react-dom@16.13.0/umd/react-dom.production.min.js"
),
Resource(
relative_package_path = "polyfill@7.8.7.min.js",
external_url = "https://unpkg.com/@babel/polyfill@7.8.7/dist/polyfill.min.js"
),
Resource(
relative_package_path = "prop-types@15.7.2.min.js",
external_url = "https://unpkg.com/prop-types@15.7.2/prop-types.min.js"
),
]
)
)

DashBase.main_registry().dash_renderer = ResourcePkg(
"dash_renderer",
RESOURCE_PATH, version = "1.5.0",
[
Resource(
relative_package_path = "dash_renderer.min.js",
dev_package_path = "dash_renderer.dev.js",
external_url = "https://unpkg.com/dash-renderer@1.5.0/dash_renderer/dash_renderer.min.js"
),
Resource(
relative_package_path = "dash_renderer.min.js.map",
dev_package_path = "dash_renderer.dev.js.map",
dynamic = true,
),
]
)


end


end # module
13 changes: 0 additions & 13 deletions src/Front.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
module Front
import JSON, JSON2, PlotlyBase


to_dash(t::Any) = t
from_dash(::Type{Any}, t::Any) = t


function from_dash(::Type{PlotlyBase.Plot}, t)
data = PlotlyBase.GenericTrace[PlotlyBase.GenericTrace(tr) for tr in t.data]
layout = PlotlyBase.Layout(t.layout)
PlotlyBase.Plot(data, layout)
end

#FIXME It's not elegant, but I didn't find elegant solution
JSON2.write(io::IO, p::PlotlyBase.Plot; kwargs...) = write(io, JSON.json(p))
end
2 changes: 1 addition & 1 deletion src/handler/processors/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end
function _push_to_res!(res, value, out)
!(value isa NoUpdate) && push!(res,
dep_id_string(out.id) => Dict(
Symbol(out.property) => Front.to_dash(value)
Symbol(out.property) => DashBase.to_dash(value)
)
)
end
Expand Down
12 changes: 0 additions & 12 deletions test/Project.toml

This file was deleted.

Loading