条件面板,其中条件是输入的长度
conditional panel where condition is length of input
我无法理解为什么我的条件 input.wave1.length > 1
不起作用。
我希望“整体曲线”复选框不会出现,除非input$loess
并且如果在第 1 波或第 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
我无法理解为什么我的条件 input.wave1.length > 1
不起作用。
我希望“整体曲线”复选框不会出现,除非input$loess
并且如果在第 1 波或第 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