...
Hi there, I cross post something from stackoverflow (collapse sidebar while using appendTab) as I still could not figure it out.
I try to collapse the sidebar in the new tab once one of the marker in the example is clicked. Sidebar should stay in Main Dashboard tab
Little example app with data
library(shiny)
library(leaflet)
library(shinydashboard)
library(purrr)
library(shinyjs)
pts <- data.frame(
id= letters[seq( from = 1, to = 10 )],
x = rnorm(10, mean = -93.625),
y = rnorm(10, mean = 42.0285))
ui part with id="Sidebar"
for the sidebar element which should be hidden and useShinyjs()
ui <- dashboardPage(
dashboardHeader(title = "Test"),
dashboardSidebar(
sidebarMenu(id="Sidebar",
actionLink("remove", "Remove detail tabs"))),
dashboardBody(
useShinyjs(), # not really sure where this has to go?
tabsetPanel(
id = "tabs",
tabPanel(
title = "Main Dashboard",
value = "page1",
fluidRow(tabsetPanel(id='my_tabsetPanel',
tabPanel('Map1',
leafletOutput('map1')
)))))))
server part where I add an Eventobserver()
within the appendTab
which should recognize that a new tab is opened and hide the sidebar
###server
server <- function(input, output, session) {
tab_list <- NULL
output$map1 <- renderLeaflet({
leaflet() %>%
addTiles() %>%
setView(-93.65, 42.0285, zoom = 6)
})
observe({
input$my_tabsetPanel
tab1 <- leafletProxy('map1', data = pts) %>%
clearMarkers() %>%
addCircleMarkers(lng = ~x, lat = ~y, radius = 4, layerId = ~id)})
observeEvent(input$map1_marker_click, {
clickedMarker <- input$map1_marker_click[1]
tab_title <- paste(clickedMarker)
appendTab(inputId = "my_tabsetPanel",
tabPanel(
tab_title,
fluidRow(
box('test')
)))
tab_list <<- c(tab_list, tab_title)
observeEvent(input$tabs == "my_tabsetPanel", { #also not sure if this is at the right place?
shinyjs::hide(id = "Sidebar")
})
updateTabsetPanel(session, "my_tabsetPanel", selected = tab_title)
})
observeEvent(input$remove,{
tab_list %>%
walk(~removeTab("my_tabsetPanel", .x))
tab_list <<- NULL
})}
shinyApp(ui = ui, server = server)
Thanks for any input