rstudio / shinydashboard

Shiny Dashboarding framework
https://rstudio.github.io/shinydashboard/
Other
893 stars 298 forks source link

Rendering messages in header dropdownMenu in shiny #294

Open sankarachari opened 6 years ago

sankarachari commented 6 years ago

Ui code: UI code: ui <- shinyUI( dashboardPage(skin = "red", dashboardHeader(title = "PSMRI", dropdownMenuOutput("msgOutPut"))))

Server code: output$msgOutPut <- renderMenu({ msgs <- apply(read.csv("messages.csv"), 1,function(row){ messageItem(from = row[["from"]], message = row[["message"]]) }) dropdownMenu(type = "messages", .list = msgs) })

Error: > runApp('My Dashboard/NewPSMRI.R') Error in FUN(X[[i]], ...) : Expected tag to be of type li

I am not able to trace the error where I did mistake. Can anyone help me out in this error.

I would like to automate the messages in the dropdown list located in the header of the UI.

Thanks in advance.

ismirsehregal commented 5 years ago

You might want to adapt this to your csv input:

library(shiny)
library(shinydashboard)

somedata <- data.frame(from=letters, message=LETTERS)
write.csv(somedata, file="messages.csv")

ui <- dashboardPage(skin = "red",
  dashboardHeader(title = "PSMRI", dropdownMenuOutput("msgOutPut")),
  dashboardSidebar(),
  dashboardBody()
)

server <- function(input, output) {

  output$msgOutPut <- renderMenu({
    csvdata <- read.csv("messages.csv")
    print(csvdata)
    msgs <- apply(csvdata, 1, function(row) {
      messageItem(from = row[["from"]], message = row[["message"]])
    })
    print(msgs)
    dropdownMenu(type = "messages", .list = msgs)
  })
}

shinyApp(ui, server)

Also take a look here.