|
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 -------------------------------------------------------- |
2 | 9 |
|
3 | 10 | library(shiny) |
4 | 11 | library(psych) |
5 | | -# Define UI for application that draws a histogram |
| 12 | + |
| 13 | +# User interface ---------------------------------------------------------- |
| 14 | + |
6 | 15 | 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 |
29 | 32 | ), |
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 |
34 | 39 | ) |
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 | + }) |
49 | 58 | } |
50 | 59 |
|
51 | | -# Run the application |
52 | | -shinyApp(ui = ui, server = server) |
| 60 | +# Run application --------------------------------------------------------- |
53 | 61 |
|
| 62 | +shinyApp(ui = ui, server = server) |
0 commit comments