snotskie / EpistemicNetworkAnalysis.jl

Native implementation of Epistemic Network Analysis written in the Julia programming language. Based on rENA 0.2.0.1.
https://snotskie.github.io/EpistemicNetworkAnalysis.jl/
GNU General Public License v3.0
6 stars 2 forks source link

add example for making a Dash interface? #47

Open snotskie opened 11 months ago

snotskie commented 11 months ago

for #13, an example could be building an interface (a la shiny, etc.) using https://github.com/plotly/Dash.jl

snotskie commented 11 months ago

example using the icqe23 intro model:

using Dash
using Plots
using EpistemicNetworkAnalysis

# Load ENA package
using EpistemicNetworkAnalysis

# Load sample dataset, codes from my first year on hormone replacement therapy
data = loadExample("transitions") # NOTE: To load your own data, see DataFrame(CSV.File(...))

# Derive some new codes based on old ones
deriveAnyCode!(data, :BODY, :Changes, :Mood, :Oily, :Dysphoria, :Cry)
deriveAnyCode!(data, :REFLECT, :Identity, :Longing, :Dream, :Childhood, :Family, :Name, :Letter, :Doubt, :Religion)
deriveAnyCode!(data, :LEARN, :WWW, :Experiment, :Recipe)
deriveAnyCode!(data, :PROGRESS, :Strangers, :Passed, :Out, :Affirmation)

# Add new columns for splitting the year's data in half, third, ...
data[!, :All] .= "All"
data[!, :Half] .= "First"
data[183:end, :Half] .= "Second"
data[!, :Third] .= "First"
data[122:243, :Third] .= "Second"
data[244:end, :Third] .= "Third"
data[!, :Fourth] .= "First"
data[92:183, :Fourth] .= "Second"
data[184:275, :Fourth] .= "Third"
data[276:end, :Fourth] .= "Fourth"

# List columns to use as codes, convos, and units
codes = [:DoseTracking, :SkippedDose, :Happy, :NonHappy, :Sweets, :BODY, :REFLECT, :LEARN, :PROGRESS]
conversations = [:Date]
units = [:Date]

# Run the model and plot it
model = ENAModel(data, codes, conversations, units)
p = plot(model)

# Helper to make Dash plotting easier
function make_dash_plot(p)
    dcc_graph(figure=(
        data=Plots.plotly_series(p),
        layout=Plots.plotly_layout(p)
    ))
end

# Make app
app = dash(external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"])
app.layout = html_div() do
    make_dash_plot(plot(p.subplots[1], size=(700,700))),
    make_dash_plot(plot(p.subplots[2], size=(700,700))),
    make_dash_plot(plot(p.subplots[3], size=(700,700)))
end

# Go! :)
run_server(app)

Note, this seems a little buggy, perhaps Dash isn't quite mature enough yet

image

Marking wontfix for the time being