0

I am making a shiny app that simulates an A/B test. I want to input the parameters and display the test graphically. Everything works fine except for one small thing. Scroll down to the bottom of server.R below. I am pretty sure something is going wrong with the input$Visitors inside the ggplot. When I change that to the default value of Visitors the plot shows up and it works. However, I need that value to vary with the scroll bar. With that in there, I get this error "Error in eval(expr, envir, enclos) : object 'input' not found". Any idea what is going on here? Thank you!!

ui.R

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)
    )
  )
))

server.R

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)

    })
})
Max
  • 837
  • 4
  • 11
  • 20
  • 1
    Try changing your code to `my_seq <- seq(50, input$Visitors, by = 1); s=ggplot(q, aes_string(x=my_seq))` – talat Feb 21 '15 at 09:33
  • 1
    possible duplicate of [R Shiny error object input not found](http://stackoverflow.com/questions/28483389/r-shiny-error-object-input-not-found) – Metrics Feb 21 '15 at 13:04

0 Answers0