多个选项卡的R闪亮页面刷新按钮 [英] R Shiny Page Refresh Button for Multiple Tabs
问题描述
我正在构建一个Shiny仪表板,它具有多个选项卡,每个选项卡都位于一个独立的页面中,并且可以从侧栏中的选项卡项目进行定向.
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.
我试图通过点击此处的链接在每个选项卡上添加页面刷新按钮R闪亮的页面刷新按钮
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)
基本上,现在我在标签1 中只有一个名为 SAVE 的页面刷新按钮,用于输入 aa .
Basically, now I only have the page refresh button called SAVE in tab 1 for input aa.
我想知道如何在输入 bb 和 cc .理想的解决方案是,如果用户单击任意页面上的任何保存按钮,则刷新Shiny仪表板.
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.
预先感谢
推荐答案
您必须为每个Tab创建3个不同的按钮,然后才能调用其中之一进行刷新:
You have to create 3 different buttons for each Tab, then you can call one of those to refresh:
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("b1", "Save"))
),
tabItem(tabName = "d2",
box(title = "BBB",
actionButton("b2", "Save"))
),
tabItem(tabName = "d3",
box(title = "CCC",
actionButton("b3", "Save"))
)
)
)
# UI
ui <- dashboardPage(header, sidebar, body)
# Server
server <- function(input, output, session) {
observeEvent(c(input$b1,input$b2,input$b3), {
js$refresh()
},ignoreNULL = T,ignoreInit = T)
}
# Shiny dashboard
shiny::shinyApp(ui, server)
这篇关于多个选项卡的R闪亮页面刷新按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!