I have a shiny dashboard with a navbar page which consists of two tabPanels "Summary
" and "Available Funds"
. Then "Available Funds"
consists of a tabsetPanel()
with two tabPanels "Plot"
and "Plot2"
. When "Plot"
is clicked the shiny widget in the right sidebar is displayed. Except from the 1st time that the app is loaded and I click on "Available funds"
. That happens beacause I have not clicked on "Plot"
yet and I wonder how I will connect the navbar tabPanel "Available funds"
with the widget display as well.
library(golem)
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = tags$body(class="skin-blue sidebar-mini control-sidebar-open", dashboardPagePlus(
header = dashboardHeaderPlus(
enable_rightsidebar = TRUE,
rightSidebarIcon = "gears"
),
sidebar = dashboardSidebar(),
body = dashboardBody(
golem::activate_js(),
navbarPage("Navbar!",
tabPanel("Summary"
),
tabPanel("Available funds",
tabsetPanel(
id="tabA",
type = "tabs",
tabPanel("Plot"),
tabPanel("Plot2"))
)),
tags$script(
'$("a[data-toggle=\'tab\']").click(function(){
Shiny.setInputValue("tabactive", $(this).data("value"))
})'
)
),
rightsidebar = rightSidebar(
background = "dark",
rightSidebarTabContent(
id = 1,
title = "Tab 1",
icon = "desktop",
active = TRUE,
uiOutput("sl")
)
),
title = "Right Sidebar"
)),
server = function(input, output) {
output$sl <- renderUI({
req(input$tabactive)
sliderInput(
"obs",
"Number of observations:",
min = 0, max = 1000, value = 500
)
})
observeEvent( input$tabactive , {
if (input$tabactive == "Plot"){
golem::invoke_js("showid", "sl")
} else {
golem::invoke_js("hideid", "sl")
}
})
}
)
EDITED VERSION WITH MORE TABPANELS
library(golem)
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = tags$body(class="skin-blue sidebar-mini control-sidebar-open", dashboardPagePlus(
header = dashboardHeaderPlus(
enable_rightsidebar = TRUE,
rightSidebarIcon = "gears"
),
sidebar = dashboardSidebar(),
body = dashboardBody(
golem::activate_js(),
navbarPage("Navbar!",
id = "tabactive",
tabPanel("Summary",
tabsetPanel(
id="tabB",
type = "tabs",
tabPanel("Plot3"),
tabPanel("Plot4"))),
tabPanel("Available funds",
tabsetPanel(
id="tabA",
type = "tabs",
tabPanel("Plot"),
tabPanel("Plot2"))
))
),
rightsidebar = rightSidebar(
background = "dark",
rightSidebarTabContent(
id = 1,
title = "Tab 1",
icon = "desktop",
active = TRUE,
uiOutput("sl")
)
),
title = "Right Sidebar"
)),
server = function(input, output) {
output$sl <- renderUI({
req(input$tabactive)
sliderInput(
"obs",
"Number of observations:",
min = 0, max = 1000, value = 500
)
})
output$sl2 <- renderUI({
req(input$tabactive)
sliderInput(
"obs2",
"Number of observations:",
min = 0, max = 100, value = 50
)
})
output$sl3 <- renderUI({
req(input$tabactive)
sliderInput(
"obs3",
"Number of observations:",
min = 0, max = 100, value = 50
)
})
output$sl4 <- renderUI({
req(input$tabactive)
sliderInput(
"obs4",
"Number of observations:",
min = 0, max = 100, value = 50
)
})
observe({
if (input$tabactive == "Available funds" && input$tabA == "Plot"){
golem::invoke_js("showid", "sl")
} else {
golem::invoke_js("hideid", "sl")
}
})
observe({
if (input$tabactive == "Available funds" && input$tabA == "Plot2"){
golem::invoke_js("showid", "sl2")
} else {
golem::invoke_js("hideid", "sl2")
}
})
observe({
if (input$tabactive == "Summary" && input$tabB == "Plot3"){
golem::invoke_js("showid", "sl3")
} else {
golem::invoke_js("hideid", "sl3")
}
})
observe({
if (input$tabactive == "Summary" && input$tabB == "Plot4"){
golem::invoke_js("showid", "sl4")
} else {
golem::invoke_js("hideid", "sl4")
}
})
}
)