![](/img/trans.png)
[英]R Shiny: conditionalPanel not working if used in different tabs
[英]R Shiny: conditionalPanel with renderUI not working
我正在嘗試在某些條件下顯示一些 UI。 I would like the way to choose input to vary according to the type of data: when the type selected is Type X
, I want to display a selectizeInput
and when Type Y
is selected, I want to display a sliderInput
. 為此,我在conditionalPanel
中使用uiOutput
。
這是我到目前為止所做的,遵循這個問題:
library(shiny)
library(shinyWidgets)
library(WDI)
library(DT)
library(dplyr)
foo <- data.frame(foo_name = c("A", "A", "B", "B", "C", "C"))
data <- cbind(head(mtcars), foo)
ui <- navbarPage(position = "static-top",
tabPanel(title = "Base 1",
fluidRow(
dropdownButton(
selectInput(inputId = "choice",
label = "Type of data",
choices = c("Type X",
"Type Y"),
selected = NULL,
multiple = FALSE),
conditionalPanel(
condition = "input$choice == 'Type X'",
uiOutput("machin")
),
conditionalPanel(
condition = "input$choice == 'Type Y'",
uiOutput("machin2")
),
circle = TRUE, status = "primary",
icon = icon("gear"),
width = "300px",
tooltip = tooltipOptions(title = "Outils")
),
column(width = 12,
dataTableOutput("data"))
))
)
server <- function(input, output) {
output$machin <- renderUI({
selectizeInput(inputId = "test",
label = "test",
choices = unique(data$foo_name),
selected = NULL,
multiple = T)
})
output$machin2 <- renderUI({
sliderInput("test2",
"Test2",
min = min(data$hp),
max = max(data$hp),
value = c(min(data$hp),
max(data$hp))
)
})
output$data <- renderDataTable({
if(input$choice == "Type X"){
data2 <- data %>%
filter(foo_name %in% input$test)
}
else if(input$choice == "Type Y"){
data3 <- data %>%
filter(hp %in% input$test2)
}
})
}
shinyApp(ui = ui, server = server)
這里有幾個問題:
selectizeInput
is NULL) but when Type Y is selected, some values of the dataframe are displayed我怎樣才能解決這個問題?
下次首先查看 R ( ?conditionalPanel
) 中的幫助頁面或在線查找 function。 條件是 JavaScript 表達式,因此您的 $ 符號不起作用。 它應該是一個。 (點)。
conditionalPanel(
condition = "input.choice == 'Type X'",
uiOutput("machin")
),
conditionalPanel(
condition = "input.choice == 'Type Y'",
uiOutput("machin2")
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.