2017-02-24 14 views
0

リアクティブオブジェクトに基づいてダッシュボードヘッダーのドロップダウンメニューまたは通知アイテムをレンダリングすることはできますか?私の試練はうまくいかなかった。shinydashboardのdropdownmenuのリアクティブオブジェクト

library(shiny) 
library(shinydashboard) 
ui <- dashboardPage(
    dashboardHeader(uiOutput("drop")), 
    dashboardSidebar(), 
    dashboardBody() 
) 

server <- function(input, output) { 
    values<-reactiveValues() 
    values[["numvotes"]]<-1 
    output$drop<-renderUI({ 
    dropdownMenu(type = "notifications", badgeStatus = "warning", 
       notificationItem(icon = icon("ok", lib = "glyphicon"), status = "danger", 
            paste(values[["numvotes"]],"vote(s)") 
       )    ) 
    }) 
    } 

shinyApp(ui, server) 

答えて

1

はい、これはrenderMenudropdownMenuOutputshinydashboardのドキュメントで説明されている:

https://rstudio.github.io/shinydashboard/structure.html#dynamic-content

library(shiny) 
library(shinydashboard) 
ui <- dashboardPage(
    dashboardHeader(dropdownMenuOutput("notif")), 
    dashboardSidebar(), 
    dashboardBody() 
) 

server <- function(input, output) { 
    values<-reactiveValues() 
    values[["numvotes"]] <- 1 

    output$notif <- renderMenu({ 
    dropdownMenu(type = "notifications", badgeStatus = "warning", 
        notificationItem(icon = icon("ok", lib = "glyphicon"), status = "danger", 
            paste(values[["numvotes"]], "vote(s)") 
       )    ) 
    }) 
} 

shinyApp(ui, server) 
関連する問題