Warning: Error in [[: subscript out of bounds
170: get_all_vars
169: setupF
168: visreg
167: renderPlot [/Users/.../simple.R#28]
165: func
125: drawPlot
111: reactive:plotObj
95: drawReactive
82: origRenderFunc
81: output$y2Plot
1: runApp
Why does plot() work fine, but visreg() throws this error??
Thanks!
library(shiny)
library(visreg)
Define UI for application that draws the control page
ui <- fluidPage(
column(2,
sliderInput("beta0", "beta0", min=-5, max=5, value=4, step = 1, width=150),
sliderInput("beta1", "beta1", min=-5, max=5, value=1, step = 1, width=150),
sliderInput("log_n", "log_n", min=1, max=5, value=3, step = 1, width=150),
sliderInput("x1_mean", "x1_mean", min=-5, max=5, value=0, step = 1, width=150),
sliderInput("x1_sd", "x1_sd",min=0, max=5, value=3, step = 1, width=150),
sliderInput("error_mean", "u_mean", min=-5, max=5, value=2, step = 1, width=150),
sliderInput("error_sd", "u_sd", min=0, max=5, value=3, step = 1, width=150)),
column(4,fluidRow(plotOutput("yPlot"))),
column(4,fluidRow(plotOutput("y2Plot")))
)
Define server logic
server <- function(input, output) {
x1 <- reactive({rnorm(10^input$log_n,input$x1_mean, input$x1_sd)})
u <- reactive({rnorm(10^input$log_n,input$error_mean, input$error_sd)})
y <- reactive({input$beta0 + input$beta1 * x1() + u()})
modela <- reactive({lm(y() ~ x1())})
output$yPlot <- renderPlot({plot(x1(), y())
abline(modela(), col="red")})
output$y2Plot <- renderPlot({visreg(modela())})
}
Run the application
shinyApp(ui = ui, server = server)