【发布时间】:2022-02-26 09:57:12
【问题描述】:
我显然在这里遗漏了一些东西,但我对 Shiny 应用程序还很陌生(我之前只做过几个),而且我仍在学习它们的原理。
此应用(将自行运行)适用于输入端(滑块和文本输入),但输出(应该是表格)不会显示。
代码如下:
# 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)
我在这里错过了什么?
谢谢!
【问题讨论】: