我显然在这里遗漏了一些东西,但我对闪亮的应用程序非常陌生(我以前只做过几个应用程序),而且我还在学习它们的诀窍。
这个应用程序(它将自己运行)工作在输入端(一个滑块和一个文本输入),但是输出(应该是一个表)不会显示。
以下是代码:
# 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)
我在这里错过了什么?
谢谢!
发布于 2022-02-25 17:57:12
你有一些事情要做
将滑块的输入改为"result"
MyBMI
和MyAge
,但在后面,您可以这样引用它们:data$BMI
和data$age
以下是修正后的版本
# 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)
https://stackoverflow.com/questions/71273458
复制相似问题