Skip to content

Commit 656026b

Browse files
committed
Display table on web app
1 parent f33378d commit 656026b

4 files changed

Lines changed: 226 additions & 50 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ vignettes/*.pdf
3131
# Temporary files created by R markdown
3232
*.utf8.md
3333
*.knit.md
34+
.Rproj.user
Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,62 @@
1-
# This script is the source for a web app to plot block randomization
1+
# Documentation -----------------------------------------------------------
2+
3+
# Web app to produce block randomization trials
4+
# Author: Deepak Sharma
5+
# Computer Programmer, JPNATC - AIIMS
6+
# Date: 28 March, 2017
7+
8+
# Import libraries --------------------------------------------------------
29

310
library(shiny)
411
library(psych)
5-
# Define UI for application that draws a histogram
12+
13+
# User interface ----------------------------------------------------------
14+
615
ui <- fluidPage(
7-
8-
# Application title
9-
titlePanel("Block randomization in R"),
10-
11-
# Sidebar with a slider input for number of bins
12-
sidebarLayout(
13-
sidebarPanel(
14-
sliderInput("trials",
15-
"Number of trials:",
16-
min = 1,
17-
max = 300,
18-
value = 150),
19-
sliderInput("blocks",
20-
"Number of blocks:",
21-
min = 1,
22-
max = 10,
23-
value = 3),
24-
sliderInput("cases",
25-
"Number of cases:",
26-
min = 1,
27-
max = 4,
28-
value = 2)
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
2932
),
30-
31-
# Show a plot of the generated distribution
32-
mainPanel(
33-
plotOutput("distPlot")
33+
sliderInput(
34+
"cases",
35+
"Number of cases:",
36+
min = 1,
37+
max = 4,
38+
value = 2
3439
)
35-
)
36-
)
37-
38-
# Define server logic required to draw a histogram
39-
server <- function(input, output) {
40-
41-
output$distPlot <- renderPlot({
42-
# generate bins based on input$bins from ui.R
43-
x <- input$blocks
44-
y <- input$trials
45-
condition <- block.random( n= input$trials,c(block = input$blocks,drug = 2))
46-
# draw the histogram with the specified number of bins
47-
plot(condition[,2], condition[,3], col = 'darkgray', border = 'white')
48-
})
40+
),
41+
42+
# Show result table
43+
mainPanel(tableOutput("filetable"))
44+
))
45+
46+
47+
# Server ------------------------------------------------------------------
48+
49+
server <- function(input, output)
50+
{
51+
output$filetable <- renderTable({
52+
condition <-
53+
block.random(n = input$trials, c(block = input$blocks, drug = input$cases))
54+
output <- data.frame(condition)
55+
colnames(output) <- c("Block", "to_be_discarded", "Case")
56+
output[,-2]
57+
})
4958
}
5059

51-
# Run the application
52-
shinyApp(ui = ui, server = server)
60+
# Run application ---------------------------------------------------------
5361

62+
shinyApp(ui = ui, server = server)
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
"","Block no.","Case"
2+
"S1",1,2
3+
"S2",1,2
4+
"S3",1,1
5+
"S4",1,2
6+
"S5",1,1
7+
"S6",1,1
8+
"S7",2,2
9+
"S8",2,1
10+
"S9",2,1
11+
"S10",2,2
12+
"S11",2,2
13+
"S12",2,1
14+
"S13",3,1
15+
"S14",3,1
16+
"S15",3,2
17+
"S16",3,1
18+
"S17",3,2
19+
"S18",3,2
20+
"S19",4,2
21+
"S20",4,1
22+
"S21",4,2
23+
"S22",4,1
24+
"S23",4,2
25+
"S24",4,1
26+
"S25",5,1
27+
"S26",5,2
28+
"S27",5,2
29+
"S28",5,1
30+
"S29",5,2
31+
"S30",5,1
32+
"S31",6,1
33+
"S32",6,1
34+
"S33",6,2
35+
"S34",6,2
36+
"S35",6,1
37+
"S36",6,2
38+
"S37",7,1
39+
"S38",7,2
40+
"S39",7,2
41+
"S40",7,2
42+
"S41",7,1
43+
"S42",7,1
44+
"S43",8,1
45+
"S44",8,2
46+
"S45",8,1
47+
"S46",8,2
48+
"S47",8,2
49+
"S48",8,1
50+
"S49",9,2
51+
"S50",9,2
52+
"S51",9,1
53+
"S52",9,1
54+
"S53",9,1
55+
"S54",9,2
56+
"S55",10,2
57+
"S56",10,1
58+
"S57",10,2
59+
"S58",10,1
60+
"S59",10,2
61+
"S60",10,1
62+
"S61",11,1
63+
"S62",11,1
64+
"S63",11,1
65+
"S64",11,2
66+
"S65",11,2
67+
"S66",11,2
68+
"S67",12,1
69+
"S68",12,1
70+
"S69",12,1
71+
"S70",12,2
72+
"S71",12,2
73+
"S72",12,2
74+
"S73",13,2
75+
"S74",13,1
76+
"S75",13,2
77+
"S76",13,2
78+
"S77",13,1
79+
"S78",13,1
80+
"S79",14,2
81+
"S80",14,1
82+
"S81",14,2
83+
"S82",14,1
84+
"S83",14,2
85+
"S84",14,1
86+
"S85",15,2
87+
"S86",15,2
88+
"S87",15,2
89+
"S88",15,1
90+
"S89",15,1
91+
"S90",15,1
92+
"S91",16,1
93+
"S92",16,1
94+
"S93",16,2
95+
"S94",16,2
96+
"S95",16,2
97+
"S96",16,1
98+
"S97",17,1
99+
"S98",17,1
100+
"S99",17,1
101+
"S100",17,2
102+
"S101",17,2
103+
"S102",17,2
104+
"S103",18,2
105+
"S104",18,2
106+
"S105",18,1
107+
"S106",18,1
108+
"S107",18,1
109+
"S108",18,2
110+
"S109",19,2
111+
"S110",19,1
112+
"S111",19,2
113+
"S112",19,1
114+
"S113",19,2
115+
"S114",19,1
116+
"S115",20,1
117+
"S116",20,2
118+
"S117",20,2
119+
"S118",20,2
120+
"S119",20,1
121+
"S120",20,1
122+
"S121",21,2
123+
"S122",21,1
124+
"S123",21,2
125+
"S124",21,1
126+
"S125",21,2
127+
"S126",21,1
128+
"S127",22,1
129+
"S128",22,2
130+
"S129",22,1
131+
"S130",22,2
132+
"S131",22,1
133+
"S132",22,2
134+
"S133",23,2
135+
"S134",23,1
136+
"S135",23,2
137+
"S136",23,1
138+
"S137",23,2
139+
"S138",23,1
140+
"S139",24,2
141+
"S140",24,1
142+
"S141",24,2
143+
"S142",24,2
144+
"S143",24,1
145+
"S144",24,1
146+
"S145",25,1
147+
"S146",25,1
148+
"S147",25,2
149+
"S148",25,2
150+
"S149",25,1
151+
"S150",25,2

block_randomization.r

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
install.packages("psych")
1+
# Include psych package
2+
23
library(psych)
34

4-
condition <- block.random( n= 150,c(block = 3,drug = 2))
5-
headTail(condition)
6-
write.csv(condition,"randomized_design.csv")
7-
pairs.panels(condition)
8-
plot(condition,type = 'l')
5+
# Generate N number of trials ---------------------------------------------
6+
7+
n <- 150
8+
not_useful <- 3
9+
cases <- 2
10+
11+
# Generate randomized trials for N = 150 ----------------------------------
12+
13+
trials <- block.random(n,c(not_useful, cases))
14+
headTail(trials)
15+
output <- data.frame(trials)
16+
colnames(output) <- c("Block no.","to_be_discarded","Case")
17+
18+
# Write CSV file ----------------------------------------------------------
19+
20+
# Discarding second column which contains non-relevent data
21+
write.csv(output[,-2],"Randomized_trials.csv")
22+
pairs.panels(trials)
23+
plot(trials,type = 'l')

0 commit comments

Comments
 (0)