0
我有一個ShinyDashboard頁面,其中包含標題內的notificationMenu。我從儀表板中的頁面內更新這些通知。這很好,但在更新通知項目後,用戶被重定向到應用程序的第一個選項卡 - 這是一個奇怪的行爲。我希望即使在更新被觸發後,仍然停留在當前頁面。有沒有人有解釋?正在更新notificationMenuOutput - 奇怪的重定向到其他標籤
library(shiny)
library(shinydashboard)
library(dplyr)
ui <- dashboardPage(dashboardHeader(dropdownMenuOutput("notificationMenu")),
dashboardSidebar(sidebarMenu(menuItem("Page 1", tabName = "page1"),
menuItem("Page 2", tabName = "page2"))),
dashboardBody(tabItems(
tabItem(tabName = "page1", h4("This is Page 1")),
tabItem(tabName = "page2",
textInput("text", "Enter News:", "New News."),
actionButton("save", "Save")))))
server <- function(input, output, session){
raw_news <- reactiveValues()
# Intial Header News: 1 Message from Admin
raw_news$news <- data_frame(from = "Admin", text = "this is a message")
# The notifications in header
output$notificationMenu <- renderMenu({
raw_news <- raw_news$news
dropdownMenu(
messageItem(raw_news$from[1], raw_news$text[1])
)
})
# save a new notification
observeEvent(input$save, {
raw_news$news <- data.frame(from = "User", text = input$text)
})
}
shinyApp(ui = ui, server = server)
問題:https://github.com/rstudio/shinydash board/issues/229 //解決方法:https://github.com/rstudio/shinydashboard/issues/232 – shosaco