我正在尝试使用RShiny部署简单的线性回归模型。但是每当我运行该应用程序并给出一个随机的预测值,而不是单值输出时,我就会得到一个完整拟合值(14个值)的表作为输出。我使用了以下代码:
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)
答案 0 :(得分:0)
从评论中复制:
我建议您删除该attach()
,因为它不是必需的,它可能会使事情搞砸。
坦白地说,我建议不要使用attach()
:另请参见:Do you use attach() or call variables by name or slicing?