代碼如下:
ui <- fluidPage(
titlePanel("Lesson 1 Introduction to Sample Size Calcuation in Clinical Trials"),
sidebarLayout(
sidebarPanel(
#Select the sample size;
selectInput(inputId="size", label="Sample size you choose", choices=seq(1, 30, by=1), selected=5),
numericInput("seed","Seed Number to generate Sample is", 12345, min=0, max=20000),
numericInput("simn", "Number of Trials", 2, min=1, max=1000)
),
mainPanel(
h1("Why should we consider Sample Size in Clinical Trials?"),
h3("Because insufficient size will make an effective drug fail to show efficacy", style = "font-family: 'times'; font-si16pt"),
br(),
br(),
strong("An example"),
br(),
em("Suppose a new tech which improves the quality, which is measured by use of the quality in kg, of the product.
The previous standard is mean of 3kg, while now the tech patent owner claims to the quality could reach to 5kg and the standard deviation is 3.
Therefore, we would like to testify this statement by use of a trial"),
br(),
code("it could be easily calculate out to reach a 80% power, we need to sample 16, so if we sample 10, 12, 14, let's see what the power is" ),
div("This could be shown in the example", style = "color:blue"),
br(),
p("span does the same thing as div, but it works with",
span("groups of words", style = "color:blue"),
"that appear inside a paragraph."),
#Output the results you want with font of BOLD;
strong(textOutput("size")),
#output the number of trials;
strong(textOutput('n_trial')),
#The seed used to generate the data is;
strong(textOutput('seed')),
#Output the sample simulated data;
DT::dataTableOutput("dat")
)
)
)
server<-function(input, output){
if(!require(DT)) install.packages("DT")
library(DT)
output$size <- renderText({
paste("You have selected sample size is", input$size)
})
output$n_trial<-renderText({
paste("You have done", input$simn, "trials")
})
output$seed<-renderText({
paste("The seed used to generate the data is", is.numeric(input$seed))
})
output$dat<-DT::renderDataTable(DT::datatable({
x<-matrix(0, nrow=input$simn, ncol=input$size)
for(i in 1:input$simn){
x[i,]<-rnorm(input$size,0,1)
}
x
}))
}
shinyApp(ui=ui, server=server)
- Q&A.R