【问题标题】:Deploying simple linear regression model using RShiny使用 R Shiny 部署简单的线性回归模型
【发布时间】:2020-06-03 11:10:21
【问题描述】:

我正在尝试使用 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)

【问题讨论】:

  • 我建议去掉那个attach(),因为它不是必需的,而且可能会搞砸。
  • 太棒了!有效。谢谢。

标签: r shiny regression linear-regression shinyapps


【解决方案1】:

复制自cmets:

我建议去掉那个attach(),因为它不是必需的,而且它可能会搞砸。

坦率地说,我建议不要使用attach():另请参阅:Do you use attach() or call variables by name or slicing?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-13
    • 2021-11-26
    • 2018-04-28
    • 2018-10-03
    • 1970-01-01
    • 2011-02-24
    • 2018-12-13
    相关资源
    最近更新 更多