应用 conditionalPanel 逻辑,其中一个 switchInput 设置为 TRUE,并且滑块具有不同的输入
Applying conditionalPanel logic where one switchInput is set to TRUE, and a slider has different inputs
我正在实现一个 R Shiny 应用程序,我的 Javascript 技能并不强。
我正在努力想出 conditionalPanel()
中的条件逻辑。如何让 id3
仅在 id1
设置为 TRUE 时显示,并且滑块范围 id2
有不同的选择?
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
materialSwitch(inputId = "id1", label = "Do I want this on?", value = FALSE, status = "primary"),
sliderTextInput(inputId = "id2", label = "Show below if the range is greater than 0", choices = 2000:2018, selected = rep(2018, 2)),
br(), br(),
conditionalPanel("input.id1 && input.id2[1] != input.id2[2]",
materialSwitch(inputId = "id3", label = "To show based on conditions above.", value = FALSE, status = "primary")
)
)
server <- function(input, output) {}
shinyApp(ui = ui, server = server)
我也玩过shinyjs
包,但我也没有成功(下面尝试):
library(shiny)
library(shinyWidgets)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
materialSwitch(inputId = "id1", label = "Do I want this on?", value = FALSE, status = "primary"),
sliderTextInput(inputId = "id2", label = "Show below if the range is greater than 0", choices = 2000:2018, selected = rep(2018, 2)),
br(), br(),
hidden(
p(id = "element", materialSwitch(inputId = "id3", label = "To show based on conditions above.", value = FALSE, status = "primary"))
)
)
server <- function(input, output) {
observe({
if (input$id1 == TRUE && (input$id2[1] != input$id2[2])) {
show("element")
}
})
}
shinyApp(ui = ui, server = server)
我忘了 Javascript 使用零基索引,这与 R 不同。
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
materialSwitch(inputId = "id1", label = "Do I want this on?", value = FALSE, status = "primary"),
sliderTextInput(inputId = "id2", label = "Show below if the range is greater than 0", choices = 2000:2018, selected = rep(2018, 2)),
br(), br(),
conditionalPanel("input.id1 && input.id2[0] != input.id2[1]",
materialSwitch(inputId = "id3", label = "To show based on conditions above.", value = FALSE, status = "primary")
)
)
server <- function(input, output) {}
shinyApp(ui = ui, server = server)
我正在实现一个 R Shiny 应用程序,我的 Javascript 技能并不强。
我正在努力想出 conditionalPanel()
中的条件逻辑。如何让 id3
仅在 id1
设置为 TRUE 时显示,并且滑块范围 id2
有不同的选择?
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
materialSwitch(inputId = "id1", label = "Do I want this on?", value = FALSE, status = "primary"),
sliderTextInput(inputId = "id2", label = "Show below if the range is greater than 0", choices = 2000:2018, selected = rep(2018, 2)),
br(), br(),
conditionalPanel("input.id1 && input.id2[1] != input.id2[2]",
materialSwitch(inputId = "id3", label = "To show based on conditions above.", value = FALSE, status = "primary")
)
)
server <- function(input, output) {}
shinyApp(ui = ui, server = server)
我也玩过shinyjs
包,但我也没有成功(下面尝试):
library(shiny)
library(shinyWidgets)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
materialSwitch(inputId = "id1", label = "Do I want this on?", value = FALSE, status = "primary"),
sliderTextInput(inputId = "id2", label = "Show below if the range is greater than 0", choices = 2000:2018, selected = rep(2018, 2)),
br(), br(),
hidden(
p(id = "element", materialSwitch(inputId = "id3", label = "To show based on conditions above.", value = FALSE, status = "primary"))
)
)
server <- function(input, output) {
observe({
if (input$id1 == TRUE && (input$id2[1] != input$id2[2])) {
show("element")
}
})
}
shinyApp(ui = ui, server = server)
我忘了 Javascript 使用零基索引,这与 R 不同。
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
materialSwitch(inputId = "id1", label = "Do I want this on?", value = FALSE, status = "primary"),
sliderTextInput(inputId = "id2", label = "Show below if the range is greater than 0", choices = 2000:2018, selected = rep(2018, 2)),
br(), br(),
conditionalPanel("input.id1 && input.id2[0] != input.id2[1]",
materialSwitch(inputId = "id3", label = "To show based on conditions above.", value = FALSE, status = "primary")
)
)
server <- function(input, output) {}
shinyApp(ui = ui, server = server)