Skip to content

Commit

Permalink
Merge pull request #1 from UBC-MDS/app_skeleton_with_docker
Browse files Browse the repository at this point in the history
first commit
  • Loading branch information
shyan0903 authored Mar 11, 2022
2 parents 4471dff + 3db8dc6 commit f21cb5b
Show file tree
Hide file tree
Showing 6 changed files with 39,138 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM plotly/heroku-docker-r:3.6.3_heroku18

# on build, copy application files
COPY . /app/

# for installing additional dependencies etc.
RUN if [ -f '/app/onbuild' ]; then bash /app/onbuild; fi;

# look for /app/apt-packages and if it exists, install the packages contained
RUN if [ -f '/app/apt-packages' ]; then apt-get update -q && cat apt-packages | xargs apt-get -qy install && rm -rf /var/lib/apt/lists/*; fi;

# look for /app/init.R and if it exists, execute it
RUN if [ -f '/app/init.R' ]; then /usr/bin/R --no-init-file --no-save --quiet --slave -f /app/init.R; fi;

# You could install packages here, but I strongly reccomend that you use init.R instead.
# RUN R -e "install.packages('remotes', repos='http://cran.rstudio.com/')" \
# && R -e "remotes::install_github('facultyai/dash-bootstrap-components@r-release')"

# here app.R needs to match the name of the file which contains your app
CMD cd /app && /usr/bin/R --no-save -f /app/app.R

115 changes: 115 additions & 0 deletions app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
library(dash)
library(dashBootstrapComponents)
library(ggplot2)
library(plotly)
library(tidyr)
library(dplyr)

app <- Dash$new(external_stylesheets = dbcThemes$BOOTSTRAP)

df <- readr::read_csv(here::here("data", "raw", "world-data-gapminder_raw.csv"))

df[is.na(df)] <- 0

df_year_region <- df %>%
group_by(year, region) %>%
summarise(sum_co2_per_capita = sum(co2_per_capita))
app$layout(
div(
list(
dbcRow(className = "text-center bg-warning",
list(
h1("Gapminder Challenge"),
p(
paste(
"Take the challenges below to see how you understand global issues such as healthcare and finance development."
)
),
p(
paste(
"Test yourselves now!"
)
)
)
),
dbcRow(
list(
dbcCol(dbcCard(className = "m-3 p-3",
list(
dccGraph(id = "bar_chart"),
dccSlider(
id = "slider",
min = 1914,
max = 2014,
step = 10,
marks = list(
"1914" = "1914",
"1924" = "1924",
"1934" = "1934",
"1944" = "1944",
"1954" = "1954",
"1964" = "1964",
"1974" = "1974",
"1984" = "1984",
"1994" = "1994",
"2004" = "2004",
"2014" = "2014"
),
value = 1914,
),
dccDropdown(
id = "dropdown",
options = c(
"Americas",
"Asia",
"Europe",
"Oceania",
"Africa"
),
value = c("Americas", "Oceania", "Africa"),
multi = TRUE
)
)
),
md = 6
),
dbcCol(dbcCard(className = "m-3 p-3", div(
"Card 2"
)), md = 6)
)
),
dbcRow(
list(
dbcCol(dbcCard(className = "m-3 p-3",div(
"Card 3"
)), md = 6),
dbcCol(dbcCard(className = "m-3 p-3",div(
"Card 4"
)), md = 6)
)
)
)
)
)


app$callback(
output("bar_chart", "figure"),
list(
input("slider", "value"),
input("dropdown", "value")
),
function(selected_year, selected_regions) {
p <- ggplot(df_year_region %>%
filter(year == selected_year, region %in% selected_regions)) +
aes(y = reorder(region, sum_co2_per_capita, ),
x = sum_co2_per_capita, fill = region) +
geom_bar(stat = "identity") +
labs(x = "CO2 emissions per capita", y = "Region")
ggplotly(p) %>% layout()
}
)


app$run_server(host = "0.0.0.0")

3 changes: 3 additions & 0 deletions apt-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
libcurl4-openssl-dev
libxml2-dev
libv8-3.14-dev
Loading

0 comments on commit f21cb5b

Please sign in to comment.