我有一个像这样构建的shinydashboard应用程序:我有一个tabItem,里面有一个盒子(带着我的selectInput)和一个tabBox。在盒子里,我有不同的过滤器,而在tabBox中,我有两个tabPanel (tab1和tab2)。我想要的是禁用selectInput (只有一个)用于tab1,并为tab2启用它。我正试图用shinyJS包来做这件事,但我遇到了一些困难。
library(shiny)
library(shinydashboard)
library(shinyjs)
df <- data.frame(id = 1:10, name = paste(letters[1:10], sep = ""))
body <- dashboardBody(
shinyjs::useShinyjs(),
fluidRow(
tabBox(
title = "First tabBox",
# The id lets us use input$tabset1 on the server to find the current tab
id = "tabset", height = "250px",
tabPanel("tab1", "First tab content"),
tabPanel("tab2", "Tab content 2")
),
box(title = "Variables filter",
id = "filter_box",
br(),
background = "light-blue",
solidHeader = TRUE,
width = 2,
selectInput("filter_id", "Choose id", multiple = T, choices = c("All", as.character(unique(df$id)))))
)
)
shinyApp(
ui = dashboardPage(
dashboardHeader(title = "tabBoxes"),
dashboardSidebar(),
body
),
server = function(input, output) {
observe({
validate(need(!is.null(input$tab1), ""))
if (input$tab1 == 1) {
disable("filter_id")
} else {
enable("filter_id")
}
})
}
)谢谢
发布于 2017-10-02 16:33:46
我改变了答案。下面的代码现在应该可以工作了。您必须为每个tabPanel添加一个值,然后您可以引用该值。另见此处:https://www.rdocumentation.org/packages/shinydashboard/versions/0.6.1/topics/tabBox
library(shiny)
library(shinydashboard)
library(shinyjs)
df <- data.frame(id = 1:10, name = paste(letters[1:10], sep = ""))
body <- dashboardBody(
shinyjs::useShinyjs(),
fluidRow(
tabBox(
title = "First tabBox",
# The id lets us use input$tabset1 on the server to find the current tab
id = "tabset", height = "250px",
tabPanel("tab1", value=1,"First tab content"),
tabPanel("tab2", value=2,"Tab content 2")
),
box(title = "Variables filter",
id = "filter_box",
br(),
background = "light-blue",
solidHeader = TRUE,
width = 2,
selectInput("filter_id", "Choose id", multiple = T, choices = c("All", as.character(unique(df$id)))))
)
)
shinyApp(
ui = dashboardPage(
dashboardHeader(title = "tabBoxes"),
dashboardSidebar(),
body
),
server = function(input, output) {
observe({
validate(need(!is.null(input$tabset), ""))
if (input$tabset == 1) {
disable("filter_id")
} else {
enable("filter_id")
}
})
}
)https://stackoverflow.com/questions/46525336
复制相似问题