Hi all,
I’ve been trying out stipple the last few days as an alternative to RShiny and Tableau. I’ve been able to get a nice little dashboard and I wanted to post it online to share with a few other students. By following the Genie.jl docs I’ve been able to register an app, deploy the app and provision a postgre database for it. The app is pretty simple: connect to the postgre database and display the default table. All tables in the database are listed in a drop-down menu and will update the display with the selected table. Under the hood, every time a new table is selected, a function is called to query the database and set the “data” dashboard field to the new table. Issue is that the table display doesn’t update when on heroku, but works locally. I’m very new to any web-related stuff, so I assume it’s some haphazard code on my end. Here’s the dashboard script
using Genie.Router, Genie.Renderer.Html
using Stipple
using StippleUI, StippleUI.Table, StippleUI.Range, StippleUI.BigNumber, StippleUI.Heading, StippleUI.Dashboard
using StippleCharts, StippleCharts.Charts
using LibPQ, DataFrames
conn = LibPQ.Connection(ENV["DATABASE_URL"])
tables = execute(conn,
"""
SELECT *
FROM pg_catalog.pg_tables
WHERE schemaname != 'pg_catalog' AND
schemaname != 'information_schema';
"""
) |> DataFrame
initable= execute(conn,"select * from \"P1Gen\"") |> DataFrame
Base.@kwdef mutable struct Dsh <: ReactiveModel
selected_table::R{String} = "P1Gen"
data::R{DataTable} = DataTable(initable)
tables::R{Vector{String}} = tables.tablename
end
Stipple.register_components(Dsh, StippleCharts.COMPONENTS)
model = Stipple.init(Dsh)
function query_table(table)
#conn = LibPQ.Connection(ENV["DATABASE_URL"])
t = execute(conn,
"""
select * from \"$table\"
""") |> DataFrame
#close(conn)
return(t)
end
onany(model.selected_table) do (_...)
model.data[] = query_table(model.selected_table[]) |> DataTable
end
function ui(model)
dashboard(root(model),[
heading("Stipple Practice")
row([
cell(class="st-module",
[Html.select(:selected_table;options=:tables)])
])
row([
cell(class="st-module",
[table(:data)])
])
])
end
Genie.config.run_as_server = true
Genie.config.server_host = "0.0.0.0"
Genie.config.server_port = port
route("/") do
ui(model) |> html
end
Genie.AppServer.startup()
Thanks in advance!!!