`
我初学shiny, 如下的代码怎么不能输出我想要的由随机数组成的矩阵X(以数据集的形式)? 请大佬帮忙看看。
####################代码开始######################
library(shiny)
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(
#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, byrow=TRUE)
for(i in 1:input$simn){
x[i,]<-rnorm(input$size,0,1)
}
y<-as.data.frame(x)
return(y)
}))
}
shinyApp(ui=ui, server=server)`