I am building a Shiny dashboard and it has multiple tabs, each tab is in an independent page and can be directed from the tab items in the sidebar.
I am trying to add the page refresh button on each tab by following the link here Page refresh Button in R shiny
However, I can only add it to one tab, it failed when I copied and pasted the same code for other tabs
Below is the current structure that I use:
library(shiny)
library(shinyjs)
library(shinydashboard)
jscode <- "shinyjs.refresh = function() { history.go(0); }"
header <- dashboardHeader(
)
sidebar <- dashboardSidebar(
tags$head(tags$style(HTML('.content-wrapper { height: 1500px !important;}'))),
sidebarMenu (
menuItem("A", tabName = "d1"),
menuItem("B", tabName = "d2"),
menuItem("C", tabName = "d3")
)
)
body <- dashboardBody(
useShinyjs(),
extendShinyjs(text = jscode),
tabItems(
tabItem(tabName = "d1",
box(title = "AAA",
actionButton("refresh", "Save"))
),
tabItem(tabName = "d2",
box(title = "BBB")
),
tabItem(tabName = "d3",
box(title = "CCC")
)
)
)
# UI
ui <- dashboardPage(header, sidebar, body)
# Server
server <- function(input, output, session) {
observeEvent({
input$aa
input$refresh
})
observeEvent(input$refresh, {
js$refresh();
})
observeEvent({
input$bb
})
observeEvent({
input$cc
})
}
# Shiny dashboard
shiny::shinyApp(ui, server)
Basically, now I only have the page refresh button called SAVE in tab 1 for input aa.
I am wondering how would I be able to have the same page refresh button on tab 2 and tab 3 for input bb and cc as well. The ideal solution would be having the Shiny dashboard refreshed if users click any save buttons on any pages.
Thanks in advance