Skip to content

Commit 43117cb

Browse files
committed
Add lesson on customization, and also customize tutorial website.
1 parent d9676db commit 43117cb

File tree

4 files changed

+144
-1
lines changed

4 files changed

+144
-1
lines changed

analysis/_site.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ output:
1313
workflowr::wflow_html:
1414
toc: yes
1515
toc_float: yes
16-
theme: cosmo
16+
theme: yeti
1717
highlight: textmate
18+
css: style.css

analysis/customization.Rmd

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
title: "Customizing the appearance of your workflowr website"
3+
author: "John Blischak"
4+
date: "2020-06-12"
5+
output: workflowr::wflow_html
6+
editor_options:
7+
chunk_output_type: console
8+
---
9+
10+
## Introduction
11+
12+
After you've created your workflowr website, you may wish to customize its
13+
appearance. This lesson covers a few key methods. For the full details, please
14+
read the official vignette [Customize your research
15+
website][wflow-02-customization].
16+
17+
[wflow-02-customization]: https://jdblischak.github.io/workflowr/articles/wflow-02-customization.html
18+
19+
## Change the theme
20+
21+
The website you created with workflowr is an [rmarkdown-generated website][rmd-website].
22+
The rmarkdown website settings are saved in the configuration file
23+
`analysis/_site.yml`. The default theme applied to workflowr websites is
24+
"cosmo". You should see the output section below that passes site-wide settings
25+
to `workflowr::wflow_html()`, which in turn passes these arguments to
26+
`rmarkdown::html_document()`.
27+
28+
```
29+
output:
30+
workflowr::wflow_html:
31+
toc: yes
32+
toc_float: yes
33+
theme: cosmo
34+
highlight: textmate
35+
```
36+
37+
[rmd-website]: https://bookdown.org/yihui/rmarkdown/rmarkdown-site.html
38+
39+
The available themes are from [Bootswatch][], but only a [subset are
40+
available][rmd-themes] for use with rmarkdown:
41+
42+
* cerulean
43+
* cosmo
44+
* darkly
45+
* flatly
46+
* journal
47+
* lumen
48+
* paper
49+
* readable
50+
* sandstone
51+
* simplex
52+
* spacelab
53+
* united
54+
* yeti
55+
56+
[bootswatch]: https://bootswatch.com/
57+
[rmd-themes]: https://bookdown.org/yihui/rmarkdown/html-document.html#appearance-and-style
58+
59+
As an example, this workflowr website uses the theme "
60+
`r yaml::read_yaml("analysis/_site.yml")[["output"]][["workflowr::wflow_html"]][["theme"]]`
61+
".
62+
63+
Go to [Bootswatch][] and find a few themes you like. Then try them out by
64+
changing the value of theme in `analysis/_site.yml` and rebuilding one of the
65+
pages. You can either click the Knit HTML button or use `wflow_build()`. For
66+
convenience, choose a fast running Rmd so you can quickly explore multiple
67+
themes. Note that the updated theme will only be applied to rebuilt pages, so
68+
you'll see the previous theme on different pages if you click around the
69+
website.
70+
71+
Once you've decided on a theme, commit the change to `analysis/_site.yml` while
72+
additional republishing all the Rmd files with the following command:
73+
74+
```{r republish-theme, eval=FALSE}
75+
wflow_publish("analysis/_site.yml", "Change the theme", republish = TRUE)
76+
```
77+
78+
## Change the appearance of the workflowr buttons
79+
80+
You don't have to limit yourself to the pre-made themes. If you know CSS or are
81+
willing to tinker, you can fully customize every aspect of the HTML output.
82+
You do this by [specifying a custom CSS file][custom-css]. In the context of a
83+
workflowr project, you can create the file `analysis/style.css` and then add it
84+
to the `output` section of `analysis/_site.yml`. You can of course name the CSS
85+
whatever you like. The important thing is that you save it in `analysis/` and
86+
specify the path relative to `_site.yml`.
87+
88+
```
89+
output:
90+
workflowr::wflow_html:
91+
toc: yes
92+
toc_float: yes
93+
theme: cosmo
94+
highlight: textmate
95+
css: style.css
96+
```
97+
98+
[custom-css]: https://bookdown.org/yihui/rmarkdown/html-document.html#custom-css
99+
100+
The workflowr buttons can be targeted with [CSS class selectors][mdn-class-selectors].
101+
For example, to decrease the font size of the text in all the workflowr buttons,
102+
you could add the following rule:
103+
104+
```
105+
.btn-workflowr {
106+
font-size: 75%;
107+
}
108+
```
109+
110+
[mdn-class-selectors]: https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors
111+
112+
You can also apply styles that are limited to specific types of workflowr
113+
buttons by using the corresponding class:
114+
115+
CSS class | workflowr button
116+
------------- | -------------
117+
`.btn-workflowr-report` | The button for the workflowr report at the top of the page
118+
`.btn-workflowr-fig` | The buttons for table of past versions below each figure
119+
`.btn-workflowr-sessioninfo` | The button for the session information at the bottom of the page
120+
121+
For example, to center the buttons of past versions below each figure, you could
122+
add the following rule:
123+
124+
```
125+
.btn-workflowr-fig {
126+
display: block;
127+
margin: auto;
128+
}
129+
```
130+
131+
Similar to above, once you are satisfied with the changes you've made to the
132+
appearance, you can commit the changes and republish the webpages:
133+
134+
```{r republish-css, eval=FALSE}
135+
wflow_publish(c("analysis/_site.yml", "analysis/style.css"),
136+
"Style the workflowr buttons",
137+
republish = TRUE)
138+
```

analysis/index.Rmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ During the tutorial:
1919
After the tutorial (optional content):
2020

2121
* [Local installation](local.html)
22+
* [Customizing the appearance of your workflowr website](customization.html)

analysis/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.btn-workflowr {
2+
border-radius: 1em;
3+
}

0 commit comments

Comments
 (0)