Shiny 闪亮的应用程序似乎给出了错误的答案,但只是有时候
我是新来的,对Shinny很陌生,所以我想我犯了一个新手错误。我很想知道它是什么。我创建了一个闪亮的应用程序,让我的学生练习正态分布问题。奇怪的是,有时它有正确的答案,有时却没有 这似乎不是一个取整问题,因为当我尝试输入附近的数字时,没有任何变化。我想一定是什么原因导致它在第一次加载并打印问题后重新对问题中的数字进行随机分组,但我想不出是什么原因。下面是相关的ui和服务器代码。如果你能帮忙,非常感谢Shiny 闪亮的应用程序似乎给出了错误的答案,但只是有时候,shiny,Shiny,我是新来的,对Shinny很陌生,所以我想我犯了一个新手错误。我很想知道它是什么。我创建了一个闪亮的应用程序,让我的学生练习正态分布问题。奇怪的是,有时它有正确的答案,有时却没有 这似乎不是一个取整问题,因为当我尝试输入附近的数字时,没有任何变化。我想一定是什么原因导致它在第一次加载并打印问题后重新对问题中的数字进行随机分组,但我想不出是什么原因。下面是相关的ui和服务器代码。如果你能帮忙,非常感谢 shinyUI(fluidPage( mainPanel( column(
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")}})
截图:
我添加了截图,但请清理您的代码并提供。有很多不相关的代码,更不用说它不是一个可运行的应用程序。可能的答案是什么?我运行了这个应用程序,让它打印出输入$answer2和1-percentile2,它们是相同的,即使问题标记为不正确;看起来,即使百分位2已四舍五入到小数点后两位,但从1中减去时,不会给出预期的答案-即,1-百分位2未四舍五入到小数点后两位。可能吗?事实上,我试过你的代码,但我无法重现问题,但一般来说,更合理的测试或多或少是这样的:absinput$answer3-per3u-per3l