【发布时间】:2017-12-24 14:44:31
【问题描述】:
我有一个 ShinyDashboard 页面,标题内有一个 notificationMenu。我从仪表板的页面内更新这些通知。这非常有效,但在更新通知项目后,用户被重定向到应用程序的第一个选项卡 - 这是一种奇怪的行为。即使在触发更新之后,我也希望留在当前页面。有人解释一下吗?
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)
【问题讨论】:
标签: r shiny dplyr shinydashboard