[英]Deploying simple linear regression model using RShiny
I am trying to deploy simple linear regression model using RShiny.我正在尝试使用 RShiny 部署简单的线性回归 model。 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:
但是,无论何时,我运行应用程序并给出一个随机预测值,而不是单值 output,我得到一个完整的拟合值表(14 个值)作为 output。我使用了以下代码:
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)
Copied from comments:复制自评论:
I would recommend getting rid of that attach()
, because it's not needed and it might mess things up.我建议摆脱那个
attach()
,因为它不是必需的,它可能会搞砸。
Frankly speaking, I recommend to never use attach()
: see also: Do you use attach() or call variables by name or slicing?坦率地说,我建议不要使用
attach()
:另请参阅:您使用 attach() 还是按名称或切片调用变量?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.