-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise_doc.Rmd
88 lines (75 loc) · 1.98 KB
/
exercise_doc.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
title: "Workout Plan App Components"
author: "Sam"
output:
html_document:
theme: cerulean
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message=FALSE, fig.align="center")
# load libraries ----
library(dplyr)
library(readr)
library(stringr)
library(lubridate)
library(gt)
library(htmltools)
library(downloadthis)
library(webshot)
# set working directory ----
# setwd("Programming/Exercise App")
```
```{r gt-table}
# get data ----
gdocs_url <- "https://docs.google.com/spreadsheets/d/e/2PACX-1vQliF1fPTXNk6b4cVwbkD7GmYFmyNKkG2GrzYcr21d-C02L61gZZNrk3beBEf95mQ-doWd3MweAyZKH/pub?gid=0&single=true&output=csv"
#read data from url
exercise_data <- read_csv( url(gdocs_url) )
#declare parameters ----
n_exercises = 5
n_reps = 10
n_sets = 1
n_time = 2
set_or_sets = "set"
#write in reps and sets to data of interest
data_extr <- exercise_data %>%
sample_n(n_exercises) %>%
mutate(`#` = row_number(),
`Sets/Reps/Time` =
case_when(
`Rep Or Time` == "Rep" ~ str_c(n_sets, set_or_sets, "of", n_reps, "reps", sep=" "),
`Rep Or Time` == "Time" ~ str_c(n_sets, set_or_sets, "of", n_time, "min", sep=" ")
)) %>%
select(`#`, Exercise, `Sets/Reps/Time`)
#show gt table ----
gt_table <- data_extr %>%
gt()
gt_table
```
```{r no-print, include=FALSE}
gtsave(gt_table,
"images", expand = 50,
file = "temp.png")
```
```{r download-buttons}
# provide download button functionality ----
library(downloadthis)
# download button for table to xlsx
data_extr %>%
download_this(
output_name = str_c("rand_workout_plan_", today()),
output_extension = ".xlsx",
button_label = "Download XLSX",
button_type = "primary",
)
#download button for table to png
download_file(
path = "images/temp.png",
output_name = str_c("rand_workout_plan_", today()),
output_extension = ".png",
button_label = "Download PNG",
button_type = "success",
has_icon = TRUE,
icon = "fa fa-save",
self_contained = FALSE
)
```