0

I am trying to deploy simple linear regression model using RShiny. But whenever, I run the app and give a random predictor value, instead of single valued output, I am getting a table of entire fitted values(14 values) as the output.I have used the following code:

ui <-fluidPage(
  navlistPanel(
    "Prediction Models",
    tabPanel("Case1",
             sidebarLayout(
               sidebarPanel(
                 numericInput("num","Calories",100)
               ),
               mainPanel(
                 tableOutput("x"),

               )
    )))
server<- function(input, output) {
  output$x <- renderTable({
    attach(calories_consumed)
    reg_log <- lm(`Weight gained (grams)` ~ I(`Calories Consumed`*`Calories Consumed`),data = calories_consumed)
    nw=data.frame(`Calories Consumed`=input$num)
    w=predict(reg_log,nw)
    w
  })

}
shinyApp(ui = ui, server = server)
RewaaK
  • 1
  • 1

1 Answers1

0

Copied from comments:

I would recommend getting rid of that attach(), because it's not needed and it might mess things up.

Frankly speaking, I recommend to never use attach(): see also: Do you use attach() or call variables by name or slicing?

hplieninger
  • 3,214
  • 27
  • 32