I want to update tab panels using radio buttons in bs4TabSetPanel using updatebs4TabSetPanel(). I have done this multiple number of times in shiny dashboard, however I am unable to do it in bs4Dash. I am uploading a sample code. Any help is greatly appreciated.
library(shiny)
library(shinydashboard)
home<-bs4TabSetPanel(
id = "tabset1",
side = "left",
bs4TabPanel(
tabName = "Tab 1",
active = TRUE,
fluidRow(
box(radioButtons("abc", label = "Please select an option",
choices = c("Go to tab 2" = "G2", "Go to tab 3" = "G3"), selected = character()))
)
),
bs4TabPanel(
tabName = "Tab 2",
active = FALSE,
fluidRow(
h1("Welcome to tab 2")
)
),
bs4TabPanel(
tabName = "Tab 3",
active = FALSE,
fluidRow(
h1("Welcome to tab 3")
)
)
)
ui<- bs4DashPage(
navbar = bs4DashNavbar(),
sidebar = bs4DashSidebar(),
controlbar = bs4DashControlbar(),
footer = bs4DashFooter(),
title = "test",
body = bs4DashBody(
home
)
)
server<- function(input, output, session){
observeEvent(input$abc,{
if (input$abc == "G2"){
updatebs4TabSetPanel(session, "tabset1", selected = "Tab 2")
} else{
updatebs4TabSetPanel(session, "tabset1", selected = "Tab 3")
}
})
}
shinyApp(ui,server)
Hi @Bijurika in bs4Dash you need to use the numeric position of the tab rather than the tab name.
This should work, I just changed 'selected = "Tab 2"' to 'selected = 2' (and the same for "Tab 3")
library(shiny)
library(shinydashboard)
library(bs4Dash)
home<-bs4TabSetPanel(
id = "tabset1",
side = "left",
bs4TabPanel(
tabName = "Tab 1",
active = TRUE,
fluidRow(
box(radioButtons("abc", label = "Please select an option",
choices = c("Go to tab 2" = "G2", "Go to tab 3" = "G3"), selected = character()))
)
),
bs4TabPanel(
tabName = "Tab 2",
active = FALSE,
fluidRow(
h1("Welcome to tab 2")
)
),
bs4TabPanel(
tabName = "Tab 3",
active = FALSE,
fluidRow(
h1("Welcome to tab 3")
)
)
)
ui<- bs4DashPage(
navbar = bs4DashNavbar(),
sidebar = bs4DashSidebar(),
controlbar = bs4DashControlbar(),
footer = bs4DashFooter(),
title = "test",
body = bs4DashBody(
home
)
)
server<- function(input, output, session){
observeEvent(input$abc,{
if (input$abc == "G2"){
updatebs4TabSetPanel(session, "tabset1", selected = 2)
} else{
updatebs4TabSetPanel(session, "tabset1", selected = 3)
}
})
}
shinyApp(ui,server)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.