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)