It might be to do with the way I’m inserting navigation tabs? If anyone could help I’d really appreciate it.
I’m using something along the lines of this reprex as the nav_inserts are only activated if the user logs in. I know I should probably be using nav_panel_hidden though.
I’m a bit too far down the line using bslib to change to navbarPage which of course has its own updateNavbarPage() function.
There’s no problem in using nav_select when I’ve used navset_card_tab within my pages, but I can’t seem to change pages.
Thank you!
shinyApp(
ui = page_fillable(
page_navbar(title='Reprex',
padding=c(0,0,0,0),
bg='#e6e6e6',
id='tabs'
)
),
server = function(input, output, session) {
nav_insert(id='tabs',select=FALSE,position='before',
as_fill_carrier(nav_panel(title='Page 2',id='page2')))
nav_insert(id='tabs',select=TRUE,position='before',
as_fill_carrier(nav_panel(title='Page 1',id='page1',
actionButton(inputId='changePage',label='Change Page'))))
observeEvent(input$changePage,{
nav_select(
id='tabs',
selected = "page2"
)
})
})
Actually, having looked at the more typical way of doing it, this doesn’t seem to work either
shinyApp(
ui = page_fillable(
page_navbar(title='Reprex',
padding=c(0,0,0,0),
bg='#e6e6e6',
id='tabs',
nav_panel(title='Page 2',id='page2'),
nav_panel(title='Page 1',id='page1',
actionButton(inputId='changePage',label='Change Page'))
)
),
server = function(input, output, session) {
observeEvent(input$changePage,{
nav_select(
id='tabs',
selected = "page2"
)
})
})
I was expecting the page 1 to flick to page 2. In my app this is within a button that is pressed to edit a particular field, where the editor is it’s own detailed page which is successfully updated to the id to be edited, but I can’t link it to changing the page.
Use the title
, not id
. Surprisingly, nav_panel
doesn’t actually have an id
. It has a value
which defaults to title
.
nav_select(
id='tabs',
selected = "Page 2"
)
In nav_panel()
replace id
with value
. This works for me:
library(shiny)
shinyApp(
ui = page_fillable(
page_navbar(
title = 'Reprex',
padding = c(0,0,0,0),
bg = '#e6e6e6',
id ='tabs',
nav_panel(title = 'Page 2', value = 'page2'),
nav_panel(
title = 'Page 1',
value = 'page1',
actionButton(inputId = 'changePage',label = 'Change Page'))
)
),
server = function(input, output, session) {
observeEvent(input$changePage, {
nav_select(
id = 'tabs',
selected = "page2"
)
})
})