我正在制作一个模拟A / B测试的闪亮应用。我想输入参数并以图形方式显示测试。一切都很好,除了一件小事。向下滚动到下面的server.R的底部。我很确定ggplot中的输入$ Visitors出了问题。当我将其更改为访问者的默认值时,图表会显示并且可以正常工作。但是,我需要该值随滚动条而变化。有了这个,我得到这个错误"错误在eval(expr,envir,enclos):object' input'找不到"。知道这里发生了什么吗?谢谢!!
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("Optimizely AB Test"),
# Sidebar with a slider input for the number of bins
sidebarLayout(
sidebarPanel(
numericInput('Visitors', label = h3('Number of Visitors'), value=2000,
min = 0, max = 1000000),
sliderInput("sliderX", label = h3("Conversion Rate in X"),value=.2,
min = 0, max = 1),
sliderInput("sliderY", label = h3("Conversion Rate in Y"),value=.1,
min = 0, max = 1),
numericInput('Tau', label = h3('Anticipated Variance'), value=.1,
min = 0, max = 1)
),
mainPanel(
plotOutput("ABInfo",width=800,height=600)
)
)
))
library(shiny)
library(ggplot2)
shinyServer(function(input, output) {
output$ABInfo <- renderPlot({
library(shiny)
pretty_coversion=function(Xold,Yold,tau,num_visitors){
#People in x and y
nx=0
ny=0
#Conversions in x and y
cx=0
cy=0
test=vector()
diff=vector()
for(i in 1:num_visitors){
nx = nx + 1
ny = ny + 1
#print(nx)
if(runif(1,0,1) <= Xold){
cx=cx+1
}
#print(cx)
if(runif(1,0,1) <= Yold){
cy=cy+1
}
#print(cy)
Xn=cx/nx
Yn=cy/ny
diff[i]=abs(Xn-Yn)
Vn=(Xn*(1-Xn)+Yn*(1-Yn))/(ny)
#print(Vn)
test_crit=((2*log(1/.05)-log(Vn/(Vn+tau)))*((Vn*(Vn+tau))/tau))^.5
test[i]=test_crit
#print(test[i])
}
x=data.frame(test[50:num_visitors],diff[50:num_visitors])
colnames(x) = c("test","diff")
return(x)
}
q=pretty_coversion(input$sliderX,input$sliderX,input$Tau,input$Visitors)
s=ggplot(q, aes(x=50:input$Visitors)) +
geom_line(aes(y=test), colour="red")+
geom_line(aes(y=diff), colour="blue")+
ylab(label="Difference in Conversion Rate")+
xlab(label="Number of total visits")
print(s)
})
})