1
1
# Documentation -----------------------------------------------------------
2
2
3
- # Web app to produce block randomization trials
3
+ # Shiny web app to produce block randomization trials
4
4
# Author: Deepak Sharma
5
5
# Computer Programmer, JPNATC - AIIMS
6
6
# Date: 28 March, 2017
@@ -13,59 +13,47 @@ library(psych)
13
13
# User interface ----------------------------------------------------------
14
14
15
15
ui <- fluidPage(
16
- titlePanel(" Block randomization in R" ),
17
- sidebarLayout(
18
- sidebarPanel(
19
- sliderInput(
20
- " trials" ,
21
- " Number of trials:" ,
22
- min = 1 ,
23
- max = 300 ,
24
- value = 150
25
- ),
26
- sliderInput(
27
- " blocks" ,
28
- " Number of blocks:" ,
29
- min = 1 ,
30
- max = 10 ,
31
- value = 3
32
- ),
33
- sliderInput(
34
- " cases" ,
35
- " Number of cases:" ,
36
- min = 1 ,
37
- max = 4 ,
38
- value = 2
39
- ),
40
- downloadButton(' downloadData' , ' Download' )
41
- ),
42
-
43
- # Show result table
44
- mainPanel(tableOutput(" filetable" ))
45
-
46
- ))
47
-
16
+ titlePanel(' Block randomization in R' ),
17
+ sidebarLayout(
18
+ sidebarPanel(
19
+ h3(" Instructions" ),
20
+ h6(" For 150 trials enter trials = 150" ),
21
+ h6(" Factor = Desired block trials / number of cases" ),
22
+ h6(" Example: To produce a block of 6 trials" ),
23
+ h6(" Enter factor = 3 and cases = 2, since 3 * 2 = 6 " ),
24
+ textInput(" trials" , " Number of trials " ," 150" ),
25
+ textInput(" factor" , " Number of factor " ," 3" ),
26
+ textInput(" cases" , " Number of cases " ," 2" ),
27
+ radioButtons(" filetype" , " Save as " , choices = c(" txt" , " csv" , " tsv" )),
28
+ downloadButton(' trials' , ' Download trials' )
29
+ ),
30
+ mainPanel(tableOutput(' table' )
31
+ )
32
+ )
33
+ )
48
34
49
35
# Server ------------------------------------------------------------------
50
36
51
- server <- function (input , output )
52
- {
53
- output $ filetable <- renderTable({
54
- condition <-
55
- block.random(n = input $ trials , c(block = input $ blocks , drug = input $ cases ))
37
+ server <- function (input , output ){
38
+ datasetInput <- reactive({
39
+ condition <- block.random(as.numeric(input $ trials ), c(as.numeric(input $ factor ), as.numeric(input $ cases )))
56
40
output <- data.frame (condition )
57
41
colnames(output ) <- c(" Block" , " to_be_discarded" , " Case" )
58
42
data <- output [,- 2 ]
43
+ })
44
+ output $ table <- renderTable({
45
+ datasetInput()
59
46
})
60
- data <- mtcars
61
- output $ table <- renderTable({
62
- datasetInput()
63
- })
64
- output $ downloadData <- downloadHandler(
47
+
48
+ output $ trials <- downloadHandler(
65
49
filename = function () {
66
- paste(" trials" , ' .txt' , sep = ' ' )},
67
- content = function (file ){
68
- write.csv(data ,file )
50
+ paste(input $ filetype , sep = " ." )
51
+ },
52
+
53
+ # Write content in file
54
+ content = function (file ) {
55
+ sep <- switch (input $ filetype , " csv" = " ," , " tsv" = " \t " ," txt" = " " )
56
+ write.table(datasetInput(), file , sep = sep , row.names = FALSE )
69
57
}
70
58
)
71
59
}
0 commit comments