Closed jnhyeon closed 8 months ago
Hi,
This feature is already in the package. You can use tabBox()
, give it an id
and call updateTabsetPanel()
on the server side, as shown below:
library(shiny)
library(bs4Dash)
menu_tab <- lapply(1:3, function(i) {
tabPanel(
sprintf("Menu %s", i),
sprintf("Hello tab %s", i)
)
})
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
controlbar = dashboardControlbar(),
footer = dashboardFooter(),
title = "tabBox",
body = dashboardBody(
tabBox(
id = "mybox2",
title = "",
.list = menu_tab
),
selectInput(
"tab",
"Selected a tab",
choices = paste("Menu", 1:3),
"Menu 2"
)
)
),
server = function(input, output, session) {
observeEvent(input$tab, {
updateTabsetPanel(session, inputId = "mybox2", input$tab)
})
}
)
If you need to update the box element itself (not just the tabs), you can do it with input$<box_id>_box
and updateBox()
(which differentiate between the tabs and the box):
library(shiny)
library(bs4Dash)
menu_tab <- lapply(1:3, function(i) {
tabPanel(
sprintf("Menu %s", i),
sprintf("Hello tab %s", i)
)
})
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
controlbar = dashboardControlbar(),
footer = dashboardFooter(),
title = "tabBox",
body = dashboardBody(
tabBox(
id = "mybox2",
title = "",
.list = menu_tab
),
actionButton("update", "Update box")
)
),
server = function(input, output, session) {
observeEvent(input$update, {
updateBox(
session,
id = "mybox2_box",
action = "update",
options = list(
status = "danger"
)
)
})
}
)
Thank you so much! I solved it right away using updateTabsetPanel(). Thanks for your help. Have a good day :)
Thanks to your wonderful package I can enjoy my job.
I am using bs4TabCard by creating multiple tab sets. I want to create an action to select a specific set of tabs in bs4TabCard via an action button. If the updatebs4TabCard function existed, that function would have been implemented using that function's selected parameters.
Are you planning to implement the updatebs4TabCard feature? (Or, please give me some ideas to solve my problem.)
Thank you for your efforts.