假设我有以下功能
abc<-function(obs, dist, dir)
{
n=obs
if(dist=='normal1')
x<-rnorm(n, mean=0, sd=1)
if(dist=='normal2')
x<-rnorm(n, mean=0, sd=2)
if(dir=='right')
y<-qbinom(1-0.05, n, 0.5, lower.tail=TRUE, log.p=FALSE)
if(dir=='left')
y<-qbinom(0.05, n, 0.5, lower.tail=TRUE, log.p=FALSE)
if(dir=='both')
y<-qbinom(c(0.05/2, 1-(0.05/2)), n, 0.5, lower.tail=TRUE, log.p=FALSE)
P<-data.frame("mean"=mean(x), "observation"=n, "direction"=y)
return(P)
}
我在markdown文档中使用此功能来使用光泽制作交互式数据框。我使用以下代码:
library(shiny)
shinyApp(
ui <- fluidPage(
titlePanel("comparison of means"),
fluidRow(
column(3,
radioButtons("dist", h3("Distribution"),
choices = c("normal1" , "normal2"
))),
column(4,
radioButtons("dir", h4("Direction"),
choices = c("left" , "right", "both"
))),
column(5,
radioButtons("obs", h5("observation"),
choices = c(1,2,3,4,5
)))
),
tableOutput("table")
),
server<-function(input, output){
output$table<-renderTable( {abc(input$obs, input$dist, input$dir)})
}
)
当我运行应用程序时,出现以下错误:
Warning: Error in qbinom: Non-numeric argument to mathematical function
dir
在计算qbinom
函数时,字符参数可能会引起一些问题。有人可以告诉我我在哪里做错吗?
radioButtons
提供一个字符值。您必须更换input$obs
由as.numeric(input$obs)
在renderTable
。
numericInput
可能比radioButtons
观测组件更适合(as.numeric
如果使用,则不需要numericInput
)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句