3
我最近開始玩Shiny。我試圖寫些東西來證明中心極限定理。我的代碼如下:R /發光的情節不顯示在瀏覽器
ui.R:
#****************************************ui.R file code*****************************
library(shiny)
shinyUI(pageWithSidebar(headerPanel("Central Limit Theorem"),
sidebarPanel(selectInput("Distribution",
"Distribution:",
list("normal", "lognormal")),
br(),
sliderInput("sam_size",
"Sample size:",
min = 5,
max = 500,
value = 5)
),
mainPanel(tabPanel("Plot", plotOutput("plot")))
))
server.R:
#****************************************server.R file code**************************
library(shiny)
shinyServer(function(input, output){
data <- reactive(function(){Distribution <- switch(input$Distribution,
normal = rnorm,
lognormal = rlnorm,
rnorm
)
Distribution(input$sam_size*2000)})
output$plot <- reactive(function(){
Distribution <- input$Distribution
sam_size <- input$sam_size
temp <- matrix(data(), ncol=2000)
xbars <- colMeans(temp)
hist(xbars, main=paste("Sampling Distribution of the Mean Based on a", Distribution,
"distribution with n =", sam_size))})
})
當我試圖運行使用runApp()
的代碼,下面是我得到了什麼。正如你所看到的,該圖不會顯示。
怪異的一部分是,當我回到我的Rstudio,並按下「ESC」退出應用程序,在我Rstudio中顯示的情節,如下圖所示:
我想知道是否有人知道我的代碼有什麼問題。謝謝!!
非常感謝! – Alex