Skip to content

Commit

Permalink
reframed
Browse files Browse the repository at this point in the history
  • Loading branch information
consumere committed Jul 24, 2023
1 parent 585ad6a commit 0351144
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 55 deletions.
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Use the official Julia image as the base image
#FROM julia:latest
FROM consumere/shinyapps:japp
FROM julia:latest
# FROM consumere/shinyapps:japp

# Set the working directory inside the container
WORKDIR /app

# Copy the Julia Project.toml and Manifest.toml files to the container
#COPY Project.toml Manifest.toml /app/

# RUN julia -e 'using Pkg; Pkg.add.(["CSV", "DataFrames", "Dash", "PlotlyJS","Base64","Dates","Statistics"])'

RUN julia -e 'using Pkg; Pkg.add.(["Dash", "PlotlyJS","Base64","Dates","Statistics"])'
RUN julia -e 'using Pkg; Pkg.add.(["CSV", "DataFrames", "Dash", "PlotlyJS","Base64","Dates","Statistics"])'
# RUN julia -e 'using Pkg; Pkg.add.(["Dash", "PlotlyJS","Base64","Dates","Statistics"])'

# Install the Julia packages
RUN julia -e 'using Pkg; Pkg.activate("."); Pkg.instantiate();'
Expand All @@ -20,4 +19,7 @@ COPY . /app

# Set the entry point command to run the Julia script
#CMD ["julia", "apptsum.jl"]

CMD ["julia", "appts.jl"]

#docker run -p 8080:8080 consumere/shinyapps:japp
79 changes: 29 additions & 50 deletions appts.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Dash
using CSV
using DataFrames
using PlotlyJS
using Base64
using CSV
#import CSV.File
import Base64.base64decode
using Dates
using Statistics

Expand All @@ -11,15 +12,13 @@ app = Dash.dash(
"https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css",
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
],
update_title="Uploading data..."
update_title="Loading..."
)
#methods(dash)
#methods(html_div)

app.layout = html_div() do
[
html_h2("WaSiM Timeseries Analyzer"),
dcc_upload(
html_h4("WaSiM Timeseries Analyzer"),
dcc_upload(
id = "upload-data",
children = [
html_div("Drag and Drop"),
Expand All @@ -37,17 +36,30 @@ app.layout = html_div() do
),
multiple = true
),
html_div(id = "output-graph")
dcc_loading(
id = "loading",
type = "circle",
children = [
html_div(id = "output-graph")
]
)
]
end

function parse_contents(contents, filename)
printstyled("reading $filename...\n",color=:green)
# Read the contents of the uploaded file
content_type, content_string = split(contents, ',')

decoded = base64decode(content_string)
ms = ["-9999.0", "-9999", "lin", "log", "--"]
df = CSV.File(IOBuffer(decoded); delim="\t", header=1, normalizenames=true,
df = CSV.File(IOBuffer(decoded);
#delim=" ",
#ignorerepeated=true,
silencewarnings=true,
header=1,
normalizenames=true,
#ignoreemptyrows=true,
missingstring=ms, types=Float64) |> DataFrame
dropmissing!(df, 1)
for i in 1:3
Expand All @@ -57,19 +69,9 @@ function parse_contents(contents, filename)
df = df[:, Not(1:4)]
#dropmissing!(df)


printstyled("generating graphs...\n",color=:green)
###first figure ###########################
begin

#fig = PlotlyJS.make_subplots(shared_xaxes=true)
#fig = PlotlyJS.make_subplots()
# tcols = size(df)[2] - 1

# for i in 1:tcols
# PlotlyJS.add_trace!(fig,
# PlotlyJS.scatter(x=df.date, y=df[:, i], name=names(df)[i])
# )
# end

s = (filter(x->!occursin(r"year|date",x),names(df)))
#renamer - remove char _
Expand All @@ -95,8 +97,8 @@ function parse_contents(contents, filename)
#template="simple_white",
height=650*fact,
width=1200*fact,
title_text="",
xaxis_rangeslider_visible=false,
title_text="",
xaxis_rangeslider_visible=true,
#xperiod = first(df.date),
#xperiodalignment = "start",
updatemenus=[
Expand Down Expand Up @@ -127,27 +129,13 @@ function parse_contents(contents, filename)
),
]
)




# s = Symbol.(filter(x->!occursin(r"year|date",x),names(df)))
end

##############hist aggregated#################
begin
#fig_hist=plot(
fig_hist = PlotlyJS.make_subplots(shared_xaxes=true, shared_yaxes=true)

# for i in s
# PlotlyJS.add_trace!(fig_hist,
# #PlotlyJS.scatter(x=df.date, y=df[:, i], name=i)
# [
# histogram(df, x=:date, y=i, histfunc="avg", xbins_size="M1", name="hist"),
# scatter(df, mode="markers", x=:date, y=i, name="daily"),
# ])
# end

for i in s
PlotlyJS.add_trace!(fig_hist,
histogram(df, x=:date, y=i, histfunc="avg", xbins_size="M1", name=i))
Expand Down Expand Up @@ -184,13 +172,6 @@ function parse_contents(contents, filename)

fig2 = PlotlyJS.plot(dfyr, kind = "bar");

# s = (filter(x->!occursin(r"year|date",x),names(dfyr)))
# #renamer - remove chars
# for x in s
# newname=replace(x,"_"=>" ")
# #println(newname)
# rename!(df,Dict(x=>newname))
# end
s = Symbol.(filter(x->!occursin(r"year|date",x),names(dfyr)))

for i in s;
Expand All @@ -206,7 +187,7 @@ function parse_contents(contents, filename)
height=650*fact,
width=1200*fact,
title_text="yearly cumulated")

end

# function subplots1()
Expand All @@ -221,6 +202,8 @@ function parse_contents(contents, filename)
function yrmean(x::DataFrame)
#df = copy(x)
df = x
# y = filter(x->!occursin("date",x),names(df))
# s = map(y -> Symbol(y),y)
df[!, :year] = year.(df[!,:date]);
y = filter(x -> !(occursin(r"year|date", x)), names(df))
dfm = DataFrames.combine(groupby(df, :year), y .=> mean .=> y);
Expand Down Expand Up @@ -257,7 +240,7 @@ function parse_contents(contents, filename)
p2 = fig2
p3 = fig_mean
p4 = fig_hist
p = [p1 p2; p3 p4]
p = [p1 p4; p2 p3]
ti = split(filename,".")|>first
fact = 1.11
PlotlyJS.relayout!(p,
Expand Down Expand Up @@ -304,7 +287,6 @@ end
callback!(
app,
Output("output-graph", "children"),
# Output("yrsum-graph", "children"),
[Input("upload-data", "contents")],
[State("upload-data", "filename")]
) do contents, filenames
Expand All @@ -324,7 +306,4 @@ callback!(
end
end

#run_server(app, "0.0.0.0", 8052, debug = true)
run_server(app, "0.0.0.0", 8080, debug = true)
#run_server(app, debug=true)
#run_server(app, "127.0.0.1", 8050)
run_server(app, "127.0.0.1", 8080, debug = true)

0 comments on commit 0351144

Please sign in to comment.