Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example for making a Dash interface? #47

Open
snotskie opened this issue Oct 8, 2023 · 1 comment
Open

add example for making a Dash interface? #47

snotskie opened this issue Oct 8, 2023 · 1 comment
Labels
documentation Improvements or additions to documentation waiting Waiting for development elsewhere
Milestone

Comments

@snotskie
Copy link
Owner

snotskie commented Oct 8, 2023

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

@snotskie snotskie added documentation Improvements or additions to documentation bounty Help wanted to solve the issue labels Oct 8, 2023
@snotskie
Copy link
Owner Author

snotskie commented Oct 9, 2023

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

@snotskie snotskie added wontfix This will not be worked on waiting Waiting for development elsewhere documentation Improvements or additions to documentation and removed documentation Improvements or additions to documentation bounty Help wanted to solve the issue wontfix This will not be worked on labels Oct 9, 2023
@snotskie snotskie added this to the 0.9.9 milestone Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation waiting Waiting for development elsewhere
Projects
None yet
Development

No branches or pull requests

1 participant