r - 条件面板,其中条件是输入的长度
问题描述
我无法理解为什么我的病情input.wave1.length > 1
不起作用。
我想要发生的是复选框“整体曲线”不会出现,除非input$loess
并且如果在 Wave 1 或 Wave 2 手风琴中检查了超过 1 个项目。
我看不出我做错了什么。javascript中是否有条件可以完成这项工作,或者这可以用R脚本完成吗?
我的应用程序:
library(shiny)
library(shinydashboard)
library(bsplus) #accordion
#########define waves##########
wave1 <- c(
"Cayuga", "Columbia", "Erie", "Greene",
"Lewis", "Putnam", "Suffolk", "Ulster"
)
wave2 <- c(
"Broome", "Chautauqua", "Cortland", "Genesee",
"Monroe", "Orange", "Sullivan", "Yates"
)
ui <- dashboardPage(
dashboardHeader(title = "Example"),
dashboardSidebar(
tags$h4("waves:", style = "margin: 5px;"),
bs_accordion(id = "waves") %>%
#use the entire heading panel as a link instead of just title
bs_set_opts(use_heading_link = TRUE) %>%
bs_append(
title = "Wave 1",
content = checkboxGroupInput(inputId = "wave1", label = NULL,
choices = c(wave1, "All Wave 1"),
selected = "Cayuga")
) %>%
bs_append(
title = "Wave 2",
content = checkboxGroupInput(inputId = "wave2", label = NULL,
choices = c(wave2, "All Wave 2"))
),
br(),
#LOESS CURVE ####
checkboxInput(inputId = "loess", label = "Display Loess Curve",
value = FALSE),
uiOutput("loess_a"),
# uiOutput("loess_overall"),
conditionalPanel(condition = "input.loess == TRUE & input.wave1.length > 1", # should include selected > 1
checkboxInput(inputId = "loessGrouped", label = "Overall Curve",
value = TRUE)
)
),
dashboardBody(
tags$style(HTML('.checkbox label{color: red;}'))
)
)
server <- function(input, output, session) {
# conditional loess smoother #######
output$loess_a <- renderUI({
req(input$loess)
conditionalPanel(condition = "input.loess == TRUE",
sliderInput(inputId = "smoothing", label = NULL,
min = 0, max = 1, value = 1, step = 0.1))
})
}
shinyApp(ui = ui, server = server)
解决方案
要使用检查了超过 1 个项目的 Wave 1 或 Wave 2 手风琴,您可以使用以下内容:
conditionalPanel(condition = "input.loess == 1 & (input.wave1.length > 1 || input.wave2.length > 1)", # should include selected > 1
checkboxInput(inputId = "loessGrouped", label = "Overall Curve",
value = TRUE)
)
另外,你还需要input.loess == 1
在服务器端制作
推荐阅读
- c# - c# - How to get the PowerShell module version from inside the module code at runtime
- javascript - 如何在 v-text 中使用条件运算符作为 Vue.Js 组件?
- python - 如何从python中的字符串中删除反斜杠
- bash - How to remove X characters after a certain word throughout a file
- python-3.x - python3-nmap host discovery no MAC address/hostname
- arrays - How to convert IoSliceMut array into Vec
? - c# - jquery to select option data and value when each dropdown has dynamically created id
- python - Pandas not finding all values in column
- javascript - VSC 扩展 Prettier 在保存时不格式化
- ansible - Ansible: referencing hosts.yml variables in group variables with YAML anchors