Skip to content

Commit

Permalink
Fix #59 - adds shiny-tempo.Rmd and a simple shiny-server to display it
Browse files Browse the repository at this point in the history
  • Loading branch information
Bosse Nyström committed Nov 21, 2021
1 parent e94a8a7 commit 3315da3
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

*.html
!shiny/shinyapps/index.html
shiny/shinyapps/*

# config files from another repo in config
/config/
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ ORGANISATION ?= verifa

default: tempo.html

.PHONY: shiny-server
shiny-server:
cd $@ && docker build -t $(ORGANISATION)/$@ .

.PHONY: rbase-metrics
rbase-metrics:
Expand Down
8 changes: 4 additions & 4 deletions data-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ gen.team.summary <- function(summary) {
return(team.summary)
}

gen.user.delta <- function(data, id, daily.hours, api.key) {
gen.user.delta <- function(data, id, daily.hours, api.key, daily='') {
user.delta <- subset(data, team == id) %>%
group_by(user) %>%
summarise(
Expand All @@ -74,13 +74,13 @@ gen.user.delta <- function(data, id, daily.hours, api.key) {
if (! is.null(daily.hours)) {
user.delta <- merge(user.delta, daily.hours, by = "user")
} else {
if (TEMPO_DAILY == '') {
TEMPO_DAILY = 8
if (daily == '') {
daily <- 8
}
user.delta <- user.delta %>%
group_by(user) %>%
mutate(
daily = as.numeric(TEMPO_DAILY)
daily = as.numeric(daily)
)
}
user.delta <- user.delta %>%
Expand Down
12 changes: 12 additions & 0 deletions shiny-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# base image
FROM docker.io/rocker/shiny-verse:latest


## create directories
RUN mkdir -p /packages

## copy files
COPY install_packages.R /packages/install_packages.R

## install R-packages
RUN Rscript /packages/install_packages.R
1 change: 1 addition & 0 deletions shiny-server/install_packages.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install.packages("slider")
6 changes: 3 additions & 3 deletions shiny-tempo.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ check.if.empty(WD_KEY, "WD_KEY")

where TEMPO_KEY is the api key and TEMPO_START is the date you started using tempo. WD_KEY is the api key for "arbetsdagar.se", you will have to register, at least, a free account to use the service.

```{r libraries, echo = FALSE, warning = TRUE, message = TRUE}
```{r libraries, echo = FALSE, warning = FALSE, message = FALSE}
packages <- c("tidyverse", "jsonlite", "httr", "stringr", "slider", "lubridate")
check.packages(packages)
Expand Down Expand Up @@ -190,11 +190,11 @@ inputPanel(
)
```

```{r echo = FALSE}
```{r echo = FALSE, context = "server"}
renderTable({
if ( input$team.id != "" ) {
user.delta <- gen.user.delta(aggregated.data, input$team.id, working.hours, WD_KEY)
user.delta <- gen.user.delta(aggregated.data, input$team.id, working.hours, WD_KEY, TEMPO_DAILY)
}
})
Expand Down
24 changes: 20 additions & 4 deletions shiny/shiny.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
#!/bin/sh
#!/bin/sh -e

pushd $(dirname ${0})
SHINY_DOCS="tempo.html"
TEMPO_DOCS="tempo.html"
SHINY_DOCS="shiny-tempo.Rmd r-helpers.R data-helpers.R ggplot-helpers.R arbetsdag.R"

if [ ! -f "../tempo.html" ]; then
pushd ..
make
popd
fi

for doc in ${SHINY_DOCS}; do
pushd ..
make shiny-server
popd

for doc in ${TEMPO_DOCS}; do
cp ../${doc} shinyapps/.
done

for doc in ${SHINY_DOCS}; do
mkdir -p shinyapps/shiny
cp ../${doc} shinyapps/shiny/.
done

if [ -d ../config ]; then
mkdir -p shinyapps/shiny/config
cp ../config/* shinyapps/shiny/config/.
fi

docker run --rm -p 3838:3838 \
-v ${PWD}/shinyapps/:/srv/shiny-server/ \
-v ${HOME}/.Renviron:/home/shiny/.Renviron \
-u shiny \
docker.io/rocker/shiny-verse
verifa/shiny-server

popd
3 changes: 1 addition & 2 deletions shiny/shinyapps/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ <h1>Welcome to Verifa Shiny Server!</h1>
<div id="main">

<h2>Tempo Reports</h2>
<p>For the moment there's one one working report, work is on-going to create an interactive version </p>

<h2><a href="shiny/shiny-tempo.Rmd"> Shiny Tempo Report</a></h2>
<h2><a href="tempo.html"> Static Tempo Report</a></h2>

</div>
Expand Down

0 comments on commit 3315da3

Please sign in to comment.