【问题标题】:Updating notificationMenuOutput - strange redirect to other tab更新 notificationMenuOutput - 奇怪的重定向到其他选项卡
【发布时间】: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


【解决方案1】:

这确实是shinydashboard 包中的一个错误,已在版本 0.6.1.9000 中修复。今天它不在 CRAN 上,所以应该使用 github 的 devtools-Version,或者有一个解决方法:添加

sidebarMenu(id = "sidebar"

和

updateTabItems(session, "sidebar", input$sidebar)

在output$notificationMenu

更多信息:Issue and fix on Github

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多