我正在尝试构建一个闪亮的应用程序来预测用户输入一些与健康相关的问题值后的死亡概率。有一个选择框询问他们的饮酒状况(重度饮酒者,中度饮酒者和非饮酒者),然而,重度饮酒者和中度饮酒者的定义因性别而异。因此,我希望在用户输入性别后,此选择框的值会自动更新。但是,在用户输入所有问题的值并且单击“提交”按钮后,将无法计算预测概率。下面是我的代码的一部分:
ui.r
header<-dashboardHeader(title="Mortality Calculator")
sidebar<-dashboardSidebar(
sidebarMenu(
menuItem("Predicted Mortality", tabName = "prediction", icon = icon("th")),
menuItem("Plot", icon = icon("line-chart"), tabName = "plot")
)
)
body<-dashboardBody(
fluidRow(
box(
sliderInput(inputId="id.age",
label="Age",
min = 50,
max = 85,
value =50,
step=1),
selectInput(inputId = "id.gender",
label = "Select your gender",
choices = c("Male","Female")),
uiOutput('slider1'),
submitButton("Update")))
)
dashboardPage(
skin = "yellow",
header,
sidebar,
body
)
server.r
shinyServer(function(input, output){
output$slider1 <- renderUI({
slider2.value <- input$id.gender
if (slider2.value=="Male"){
selectInput("id.drinkingstatus","Select your drinking status",
choices = c("Heavy Drinker(>2 drinks per day)","Moderate Drinker(<=2 drinks per day)","Non-Drinker"))
} else{
selectInput("id.drinkingstatus","Select your drinking status",
choices = c("Heavy Drinker(>1 drink per day)","Moderate Drinker(<=1 drink per day)","Non-Drinker"))
}})
现在,在用户点击提交按钮之前,饮酒状态选择框不会更新。任何人都可以帮我修改代码,以便选择框可以自动更新吗?我也试过了conditionpanel,但问题仍然存在。我真的很感谢你的帮助!