-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmoduleBasics.txt
More file actions
34 lines (19 loc) · 852 Bytes
/
moduleBasics.txt
File metadata and controls
34 lines (19 loc) · 852 Bytes
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
How Modules work:
We have a bit of code we want to repeat in several parts of an R SHiny app.
Build two functions in global.R file
verbUI <- function(id){
ns <- NS(id)
## this holds the parts to repeat using ns("parts2refer2")
## for example, define a user input here naming in ns("myInput")
}
verb <- function(input, output, session, otherArgs, ie, reactive(input$checkbox) ){
## what to do on the server end
## input$parts2refer2 references the pieces in verbUI
## return a list of reactive expressions
}
In ui.R refer to the module as
verbUI("name4thisInstance") ## placement: where you want to see the UI appear
In server.R use callModule
newVerbFunction <- callModule(verb, "name4thisInstance", args)
Now grab the module output with
name4thisInstance()