2017-07-19 38 views
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) 

enter image description here

+0

問題:https://github.com/rstudio/shinydash board/issues/229 //解決方法:https://github.com/rstudio/shinydashboard/issues/232 – shosaco

回答

0

這的確是在shinydashboard包中的錯誤,並已被固定在0.6.1.9000版本。這不是在CRAN今天,所以從GitHub上的devtools-版本應該做的,或者有一種變通方法:添加

sidebarMenu(id = "sidebar"

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

output$notificationMenu

更多信息:Issue and fix on Github