0

I want to build a dynamic dataframe through several inputs, and then use this dataframe to get the predicted values from a mode I already had.

My code looks like this:

body <- dashboardBody(

tabItems(tabItem(tabName = "calculator",        
         box(
         flowLayout(
         numericInput('ra1', 'RA1', 0, min = 0, max = 1, step = 1),
         numericInput('ra2', 'RA2',0, min = 0, max = 1, step = 1))))

ui <- dashboardPage(
  dashboardHeader(title = "XXXXX", titleWidth = 300),
  sidebar,
  body
)


server <- function(input, output, session) {

dat <- reactive({

a <- as.integer(input$ra1) 
b <- as.integer(input$ra2)
dat = cbind(a,b)
dat = as.data.frame(dat)
dat

})

pred <- reactive({

  predict(y3, newdata = dat(), type="response")

})
}

shinyApp(ui, server)

But when running the code I get the following error:

Error in : object 'input' not found

Does anyone know what's going on? Really appreciate if anyone could give me some advice, thanks!

Cettt
  • 11,460
  • 7
  • 35
  • 58
David
  • 63
  • 5
  • Did you define a server and ui function function? Something like `server<-function(input, output, session){}` ? You might want to start with a shiny tutorial: https://shiny.rstudio.com/tutorial/ – MrFlick Aug 02 '18 at 20:39
  • @MrFlick yes I have defined those, just wanna make the code chunk simpler so I remove those – David Aug 02 '18 at 20:43
  • Well, that's where `input` comes from. It's a parameter from the server function. Please try to make a proper [shiny reproducible example](https://stackoverflow.com/questions/48343080/how-to-convert-a-shiny-app-consisting-of-multiple-files-into-an-easily-shareable) that shows the relevant parts. it sounds like your code it just in the wrong place. – MrFlick Aug 02 '18 at 20:45
  • @MrFlick Just edited! – David Aug 02 '18 at 20:53
  • 1
    This code is still not reproducible. It doesn't seem likely that you would get that particular error message given the code here, but since what you've posted ins't actually runable, I can't actually test. There are missing parenthesis, and quotes and undefined variables. – MrFlick Aug 02 '18 at 20:56

0 Answers0