闪亮的应用程序似乎给出了错误的答案,但有时只是

时间:2015-06-07 19:24:54

标签: shiny

我是新的(非常新的)闪亮所以我想我已经犯了一个菜鸟错误。我很想知道它是什么。我创建了一个闪亮的应用程序,让我的学生练习正常的分发问题。奇怪的是,有时它有正确的答案,有时候没有。

它似乎不是一个舍入问题,因为当我尝试输入附近的数字时,没有任何变化。我认为必须有一些东西必须重新引导问题中数字的随机化,因为它首先加载并打印了问题 - 但我无法想象它是什么。以下是相关的ui和服务器代码。非常感谢,如果你能帮助的话。

    shinyUI(fluidPage(

  mainPanel(  

 column(12,h3("Practice Probems For Normal Distributions")),   
column(10,h5("At an online store"))  ,
column(10, textOutput("mean") ),
column(10, textOutput("sd")),
column(10,strong("Answers to questions below should be to the nearest dollar for amounts and to two decimal places for proportions.")),
column(10,""),
column(10, textOutput("quest")),




column(10, 
         numericInput("answer", 
                      label = h5("Your answer? ="), 
                      value = 0)) ,

column(10,  textOutput("response")),

column(10,"_______________________________________________"),

#Question 2
column(10, textOutput("quest2")),



column(10, 
       numericInput("answer2", 
                    label = h5("Your answer? ="), 
                    value = 0)) ,

column(10,  textOutput("response2")),
column(10,"_______________________________________________"),

#Question 3
column(10, textOutput("quest3")),




column(10, 
       numericInput("answer3", 
                    label = h5("Your answer? ="), 
                    value = 0)) ,

column(10,  textOutput("response3")),
column(10,"_______________________________________________"),

server: 

    shinyServer(function(input, output) {

  mean = round(runif(1,100,500),0)
  sd = round(runif(1,0.1*mean,0.2*mean),0)
  #Question 1

  percentile = round(runif(1,0.05,0.95),2)
  z = qnorm(percentile)
  price=round(mean+z*sd,2)
  output$mean = renderText({paste("Sales have mean $",mean,sep="")})
  output$sd=renderText({paste("and standard deviation $",sd,sep="")})
  output$quest=renderText({paste("1. What proportion of sales are for less than $",price,"?",sep="")})
  output$response=renderText({ if (input$answer==percentile){print("correct")} else {print("Sorry. Try again")}})

 #Question 2
  percentile2 = round(runif(1,0.05,0.95),2)
  z2 = qnorm(percentile2)
  price2=round(mean+z2*sd,2)

  output$quest2=renderText({paste("2. What proportion of sales are for more than $",price2,"?",sep="")})
  output$response2=renderText({ if (input$answer2==1 - percentile2){print("correct")} else {print("Sorry. Try again")}})

  #Question 3
  per3l = round(runif(1,0.10,0.45),2)
  z3l=qnorm(per3l)
  price3l=round(mean+z3l*sd,2)
  per3u = round(runif(1,0.55,0.95),2)
  z3u=qnorm(per3u)
  price3u=round(mean+z3u*sd,2)  
  output$quest3=renderText({paste("3. What proportion of sales are between $",price3l,"and $",price3u,"?",sep="")})
  output$response3=renderText({ if (input$answer3==per3u-per3l){print("correct")} else {print("Sorry. Try again")}})

截图:

enter image description here

0 个答案:

没有答案