gpt4 book ai didi

javascript - 应用条件面板逻辑,其中一个 switchInput 设置为 TRUE,并且 slider 具有不同的输入

转载 作者:行者123 更新时间:2023-12-03 00:50:24 25 4
gpt4 key购买 nike

我正在实现一个 R Shiny 应用程序,但我的 Javascript 技能并不强。

我正在努力想出 conditionalPanel() 中的条件逻辑。如何仅在 id1 设置为 TRUE 并且 slider 范围 id2 有不同的选择时显示 id3

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)

关于javascript - 应用条件面板逻辑,其中一个 switchInput 设置为 TRUE,并且 slider 具有不同的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53073877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com