Skip to content

Commit d5f9b2f

Browse files
committed
json3
1 parent c0bac60 commit d5f9b2f

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

src/Dash.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using DashBase
33
import HTTP, JSON2, JSON3, CodecZlib, MD5
44
using Sockets
55
using Pkg.Artifacts
6+
67
const ROOT_PATH = realpath(joinpath(@__DIR__, ".."))
78
#const RESOURCE_PATH = realpath(joinpath(ROOT_PATH, "resources"))
89
include("exceptions.jl")
@@ -25,6 +26,7 @@ include("resources/application.jl")
2526
include("handlers.jl")
2627
include("server.jl")
2728
include("init.jl")
29+
include("plotly_base.jl")
2830

2931
@doc """
3032
module Dash
@@ -110,4 +112,5 @@ end
110112
JSON3.StructTypes.StructType(::Type{DashBase.Component}) = JSON3.StructTypes.Struct()
111113
JSON3.StructTypes.excludes(::Type{DashBase.Component}) = (:name, :available_props, :wildcard_regex)
112114

113-
end # module
115+
116+
end # module

src/plotly_base.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import PlotlyBase
2+
import JSON
3+
4+
function DashBase.to_dash(p::PlotlyBase.Plot)
5+
data = JSON.lower(p)
6+
pop!(data, :config, nothing)
7+
return data
8+
end

test/callbacks.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ end
399399
@test length(context.triggered) == 1
400400
@test context.triggered[1].prop_id == changed_key
401401
@test context.triggered[1].value == "test"
402-
println(value)
403402
return value
404403
end
405404
@test length(app.callbacks) == 1
@@ -426,11 +425,9 @@ end
426425
response = HTTP.handle(handler, request)
427426
@test response.status == 200
428427
s = String(response.body)
429-
println(s)
430428
resp_obj = JSON3.read(s)
431429
@test in(:multi, keys(resp_obj))
432430

433-
println(resp_obj)
434431
@test resp_obj.response.var"{\"index\":1,\"type\":\"test-out\"}".children =="test 1"
435432
@test resp_obj.response.var"{\"index\":2,\"type\":\"test-out\"}".children =="test"
436433

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Dash
2+
using PlotlyBase
3+
4+
app = dash()
5+
app.layout = html_div() do
6+
dcc_graph(id = "graph",
7+
figure = Plot(scatter(x=1:10, y = 1:10))
8+
),
9+
html_button("draw", id = "draw"),
10+
html_div("", id = "status")
11+
end
12+
13+
callback!(app, Output("graph", "figure"), Output("status", "children"), Input("draw", "n_clicks")) do nclicks
14+
plot = isnothing(nclicks) ?
15+
no_update() :
16+
Plot([scatter(x=1:10, y = 1:10), scatter(x=1:10, y = 1:2:20)])
17+
status = isnothing(nclicks) ? "first" : "second"
18+
return (plot, status)
19+
end
20+
21+
run_server(app, debug = true)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import pathlib
2+
import os.path
3+
import logging
4+
logger = logging.getLogger(__name__)
5+
6+
curr_path = pathlib.Path(__file__).parent.absolute()
7+
def jl_test_file_path(filename):
8+
return os.path.join(curr_path, "jl_plotly_graph", filename)
9+
10+
11+
12+
13+
def test_jlpg001_plotly_graph(dashjl):
14+
fp = jl_test_file_path("jlpg001_plotly_graph.jl")
15+
dashjl.start_server(fp)
16+
dashjl.wait_for_element_by_css_selector(
17+
"#graph", timeout=20
18+
)
19+
20+
dashjl.wait_for_text_to_equal("#status", "first", timeout=10)
21+
22+
dashjl.percy_snapshot(name="PlotlyBase figure layout")
23+
24+
dashjl.find_element("#draw").click()
25+
dashjl.wait_for_text_to_equal("#status", "second", timeout=10)
26+
27+
dashjl.percy_snapshot(name="PlotlyBase figure callback")

0 commit comments

Comments
 (0)