-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
373 lines (143 loc) · 5.94 KB
/
README.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# Rnightly
<!-- badges: start -->
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/Rnightly)](https://cran.r-project.org/package=Rnightly)
[![CRAN_time_from_release](https://www.r-pkg.org/badges/ago/Rnightly)](https://cran.r-project.org/package=Rnightly)
[![metacran downloads](https://cranlogs.r-pkg.org/badges/Rnightly)](https://cran.r-project.org/package=Rnightly)
[![metacran downloads](https://cranlogs.r-pkg.org/badges/grand-total/Rnightly)](https://cran.r-project.org/package=Rnightly)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://choosealicense.com/licenses/mit/)
[![Travis build status](https://travis-ci.com/feddelegrand7/Rnightly.svg?branch=master)](https://travis-ci.com/feddelegrand7/Rnightly)
[![R badge](https://img.shields.io/badge/Build%20with-♥%20and%20R-red)](https://github.com/feddelegrand7/Rnightly)
<!-- badges: end -->
The goal of `Rnightly` is to implement a Dark/Light toggle mode in your Shiny and RMarkdown user interface. You can also change the default behavior by specifying other colors.
![](https://media.giphy.com/media/xUOwV2E6HhngCpYpWw/giphy.gif)
## Installation
You can install the `Rnightly` package from [CRAN](https://CRAN.R-project.org/package=Rnightly) with:
```{r, eval=FALSE}
install.packages("Rnightly")
```
You can install the development version of `Rnightly` from Github with :
```{r, eval=FALSE}
# install.packages("remotes")
remotes::install_github("feddelegrand7/Rnightly")
```
The `Rnightly` package has two functions:
+ `use_nightly()`: set this function anywhere within your ui. It activates the [nightly](https://github.com/Fcmam5/nightly.js?utm_campaign=The%20Stash&utm_medium=email&utm_source=Revue%20newsletter) JavaScript library. The function must be run only once.
+ `nightly()`: activates the dark/light toggle mode. Look below for examples on how to use it.
## Examples
## 1.Shiny
Let's create a basic shiny app that demonstrates the features of `Rnightly`. Here the `trigElement` will determine which shiny element will trigger the Dark/Light mode. Note that it's the only mandatory argument:
```{r, eval=FALSE}
library(shiny)
library(Rnightly)
ui <- fluidPage(
use_nightly(), # Activating nightlyjs
h3("Click on the button below to toggle between a Dark/Light mode"),
actionButton(inputId = "btn", label = "Button"),
nightly(trigElement = "btn") # Make sure to provide the same id
)
server <- function(input, output){}
shinyApp(ui, server)
```
![](man/figures/Rnightlyexample1.gif)
You can specify any Shiny element to toggle your Dark/Light mode, maybe a plot ?
```{r, eval=FALSE}
library(shiny)
library(Rnightly)
ui <- fluidPage(
use_nightly(), # Activating nightlyjs
h3("Click on the Plot to toggle between a Dark/Light mode"),
plotOutput(outputId = "plt"),
nightly(trigElement = "plt")
)
server <- function(input, output){
output$plt <- renderPlot({
plot(mtcars)
})
}
shinyApp(ui, server)
```
![](man/figures/Rnightlyexample2.gif)
Now the cool part. Instead of Dark, using the `bodyColor` argument you can change the color that will be displayed when toggling:
```{r, eval=FALSE}
library(shiny)
library(Rnightly)
ui <- fluidPage(
use_nightly(),
h3("Click on the button below to toggle between a Purple/Light mode"),
actionButton(inputId = "btn", label = "Button"),
nightly(trigElement = "btn", bodyColor = "#6d6875")
)
server <- function(input, output){}
shinyApp(ui, server)
```
![](man/figures/Rnightlyexample3.gif)
You can also change the text color when toggling :
```{r, eval=FALSE}
library(shiny)
library(Rnightly)
ui <- fluidPage(
use_nightly(),
h3("Click on the button below to toggle between a Purple/Light mode"),
actionButton(inputId = "btn", label = "Button"),
nightly(trigElement = "btn", bodyColor = "#6d6875", txtColor = "#fb5607")
)
server <- function(input, output){}
shinyApp(ui, server)
```
![](man/figures/Rnightlyexample4.gif)
Further, you can set the Shiny inputs' text color that will be displayed after toggling :
```{r, eval=FALSE}
library(shiny)
library(Rnightly)
ui <- fluidPage(
use_nightly(),
h3("Click on the button below to toggle between a Purple/Light mode"),
actionButton(inputId = "btn", label = "Button"),
br(), br(), br(),
textInput(inputId = "txt1", label = "Type some text here"),
nightly(trigElement = "btn",
bodyColor = "#6d6875",
txtColor = "#fb5607",
inpTxtColor = "lightblue")
)
server <- function(input, output){}
shinyApp(ui, server)
```
![](man/figures/Rnightlyexample5.gif)
Finally, you can change the background color of Shiny inputs:
```{r, eval=FALSE}
library(shiny)
library(Rnightly)
ui <- fluidPage(
use_nightly(),
h3("Click on the button below to toggle between a Purple/Light mode"),
actionButton(inputId = "btn", label = "Button"),
br(), br(), br(),
textInput(inputId = "txt1", label = "Type some text here"),
nightly(trigElement = "btn",
bodyColor = "#6d6875",
txtColor = "#fb5607",
inpTxtColor = "lightblue",
inpBgColor = "#f07167")
)
server <- function(input, output){}
shinyApp(ui, server)
```
![](man/figures/Rnightlyexample6.gif)
2. RMarkdown
Similarly, you can implement `Rnightly` in RMarkdown:
![](man/figures/RN_example_Rmd.gif)
## Code of Conduct
Please note that the Rnightly project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.