【发布时间】:2020-08-06 23:15:27
【问题描述】:
我正在尝试缩短我的这部分代码——特别是 if、else if 语句,方法是使用 sprintf() 并更改侧边栏面板的颜色。我该怎么办?
output$calculation<-renderUI({
req(input$popDensity)
populationDensity <- input$popDensity;
likelihood <- populationDensity/500
if (likelihood()>1) {
sidebarPanel(style="background-color: red; width: 300px; height: 300px;", h3("Extreme risk!"))
} else if (likelihood()>.65){
sidebarPanel(style="background-color: orange; width: 300px; height: 300px;",
h3("Very high risk!"))
}
else if (likelihood()>.35){
sidebarPanel(style="background-color: yellow; width: 300px; height: 300px;",
h3("High risk!"))
}
else if (likelihood()>.10){
sidebarPanel(style="background-color: blue; width: 300px; height: 300px;",
h3("Moderate risk!"))
} else {
sidebarPanel(style="background-color: #39ac39; width: 300px; height: 300px;",
h3("Low risk!"))
}
})
【问题讨论】: