首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >为什么我的R发亮的应用程序显示不正确?

为什么我的R发亮的应用程序显示不正确?
EN

Stack Overflow用户
提问于 2022-02-25 17:47:03
回答 1查看 117关注 0票数 1

我显然在这里遗漏了一些东西,但我对闪亮的应用程序非常陌生(我以前只做过几个应用程序),而且我还在学习它们的诀窍。

这个应用程序(它将自己运行)工作在输入端(一个滑块和一个文本输入),但是输出(应该是一个表)不会显示。

以下是代码:

代码语言:javascript
运行
AI代码解释
复制
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

library(shiny)

ui <- fluidPage(

    # Application title
    titlePanel("CHD Risk Calculator"),

    sidebarLayout(
        sidebarPanel(
            sliderInput("BMI",
                        "Your BMI (kg/m^2 OR (703*lbs)/in^2):",
                        min = 10,
                        max = 70,
                        value = 24),
            textInput("Age",
                      "Your Age:")
        ),

        mainPanel(
           tableOutput("")
        )
    )
)

server <- function(input, output) {

    inputdata <- reactive({
        data <- data.frame(
            MyBMI = as.integer(input$BMI),
            MyAge = as.integer(input$age))
        data
    })
    
    output$result <- renderTable({
        data = inputdata()
        chdrisk = -6.293 + (0.0292*data$BMI) + (0.07409*data$age)
        resultTable = data.frame(
            Result = "Your risk of Coronary Heart Disease (CHD) is",
            Risk = chdrisk)
        resultTable
        
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

我在这里错过了什么?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2022-02-25 17:57:12

你有一些事情要做

将滑块的输入改为"result"

  • Your输入,文本名为BMI和Age,但在反应性中,您将它们称为BMI和age

  • --反应性中的数据框架有两列,MyBMIMyAge,但在后面,您可以这样引用它们:data$BMIdata$age

以下是修正后的版本

代码语言:javascript
运行
AI代码解释
复制
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

library(shiny)

ui <- fluidPage(
  
  # Application title
  titlePanel("CHD Risk Calculator"),
  
  sidebarLayout(
    sidebarPanel(
      sliderInput("BMI",
                  "Your BMI (kg/m^2 OR (703*lbs)/in^2):",
                  min = 10,
                  max = 70,
                  value = 24),
      textInput("Age",
                "Your Age:")
    ),
    
    mainPanel(
      tableOutput("result")
    )
  )
)

server <- function(input, output) {
  
  inputdata <- reactive({
    data <- data.frame(
      MyBMI = as.integer(input$BMI),
      MyAge = as.integer(input$Age))
    data
  })
  
  output$result <- renderTable({
    data = inputdata()
    chdrisk = -6.293 + (0.0292*data$MyBMI) + (0.07409*data$MyAge)
    resultTable = data.frame(
      Result = "Your risk of Coronary Heart Disease (CHD) is",
      Risk = chdrisk)
    resultTable
    
  })
}

# Run the application 
shinyApp(ui = ui, server = server)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71273458

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档