R shiny Condition a tab in the navbar based on previous tabs condition

Viewed 1386

I have the following reproducible code

Poly = data.frame(Strat = c("A","A","A","A","A","B","B","B","B","B"), long = c(174.5012, 174.5026, 174.5026, 174.5014,174.5012,174.5012 ,174.5020, 174.5020,174.5012,174.5012),lat = c(-35.84014, -35.84018, -35.84137,-35.84138,-35.84014,-35.84014,-35.84014,-35.84197,-35.84197,-35.84014))
Points = data.frame(long = c(174.5014 ,174.5017, 174.5021, 174.5023, 174.5020, 174.5017 ,174.5021 ,174.5017, 174.5021, 174.5019), lat = c(-35.84187, -35.84165, -35.84220 ,-35.84121, -35.84133, -35.84034, -35.84082, -35.84101, -35.84112, -35.84084))

library('leaflet')
library('shiny')


##### My take on Example 2
ui <- navbarPage(title = "navigation bar", 
tabPanel("Home", fluidPage(bootstrapPage(
checkboxInput("check_box", label = "Click me to continue", FALSE),
## Main text
mainPanel(
tags$div()
)

))),
tabPanel("View Data", 
   bootstrapPage(
    mainPanel(
    ),
    leafletOutput("map", width ="100%", height = "600px")
    )
)
)


server = function(input, output){

mymap <- reactive({
   leaflet() %>% addTiles(urlTemplate = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", attribution = NULL, layerId = NULL, group = NULL, options = tileOptions()) %>%  
   clearShapes() %>%
   clearMarkers() %>%      
   fitBounds(lng1 = 174.5042, lat1= -35.83814,lng2= 174.5001, lat2 = -35.8424) 
})

output$map <- renderLeaflet({
  mymap()      
})
myfun <- function(map) {
    print("adding points")
    map %>% clearShapes() %>%
    clearControls() %>% 
    clearMarkers() %>% 
    addCircles(lng = Points$long, lat = Points$lat, color = "blue",fillOpacity = 1,radius = 1)   
 }

AddStrataPoly <- function(map) {
  print("adding polygons")    
  for(i in 1:length(unique(Poly$Strat))) {
    map <- map %>% addPolygons(lng = Poly[Poly$Strat == unique(Poly$Strat)[i],]$long, lat = Poly[Poly$Strat == unique(Poly$Strat)[i],]$lat, layerId = unique(Poly$Strat)[i], color = 'gray60', options = list(fillOpacity = 0.1))
  } 
  map
}

observe({
  leafletProxy("map") %>% myfun() %>% AddStrataPoly() 
})
 }

  shinyApp(ui, server);

What I would like is to not allow users to click into the "View Data" tab unless they have clicked the check box? The tab will always exist ideally I would like to grey out the tab font as to indicate users they cannot click on it unless satisfying a condition (which will be documented) in this case a tick box.

Thanks

2 Answers
Related