-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from UBC-MDS/app_skeleton_with_docker
first commit
- Loading branch information
Showing
6 changed files
with
39,138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
libcurl4-openssl-dev | ||
libxml2-dev | ||
libv8-3.14-dev |
Oops, something went wrong.