Giter Club home page Giter Club logo

Comments (3)

wch avatar wch commented on May 12, 2024

Could you supply the UI part of the code, so that there's a complete working example?

from shinydashboard.

daherman avatar daherman commented on May 12, 2024

I solved this issue by creating a separate output for each message type in server;

output$notificationMenu <- renderMenu({
  nots <- apply(notificationData, 1, function(row) {
    notificationItem(text = row[["message"]], status = row[["status"]])
  })
  dropdownMenu(type = "notifications", .list = nots)
})

The header is built by calling dashboardHeader as follows:

header <- dashboardHeader(
  dropdownMenuOutput("messageMenu"),
  dropdownMenuOutput("notificationMenu"),
  dropdownMenuOutput("taskMenu")
)

The entire app code, including app and server:

## app.R ##
library(shiny)
library(shinydashboard)
library(googleVis)

header <- dashboardHeader(
  dropdownMenuOutput("messageMenu"),
  dropdownMenuOutput("notificationMenu"),
  dropdownMenuOutput("taskMenu")
)

sidebar <- dashboardSidebar(sidebarUserPanel("Dave",
                                             subtitle = a(
                                               href = "#", icon("circle", class = "text-success"), "Online"
                                             )),
                            sidebarMenu(
                              menuItem(
                                "Dashboard", tabName = "dashboard", icon = icon("dashboard")
                              ),
                              menuItem(
                                "Widgets", icon = icon("th"), tabName = "widgets",
                                badgeLabel = "new", badgeColor = "green"
                              )
                            ))

body <- dashboardBody(tabItems(
  tabItem(
    tabName = "dashboard",
    # infoBoxes with fill=FALSE
    fluidRow(
      # A static infoBox
      infoBox("Demand", 10 * 2, icon = icon("line-chart")),
      # Dynamic infoBoxes
      infoBoxOutput("progressBox"),
      infoBoxOutput("approvalBox")
    ),

    # infoBoxes with fill=TRUE
    fluidRow(
      infoBox("Price", 5 * 2, icon = icon("heart"), fill = TRUE),
      infoBoxOutput("progressBox2"),
      infoBoxOutput("approvalBox2")
    ),

    fluidRow(# Clicking this will increment the progress amount
      box(
        width = 4, actionButton("count", "Increment progress")
      ))
  ),

  tabItem(tabName = "widgets",
          fluidRow(
            box(plotOutput("plot1", height = 250)),
            box(
              title = "Controls",
              sliderInput("slider", "Number of observations:", 1, 100, 50)
            )
          ))
))

ui <- dashboardPage(header, sidebar, body)

server <- function(input, output) {
  set.seed(122)
  histdata <- rnorm(500)
  #get data from file
  menu.df <- read.csv("../../data/dropDownMenus2.csv")
  #partition menu data into message, notification, and task
  messageData <- subset(menu.df, type == "message")
  notificationData <- subset(menu.df, type == "notification")
  taskData <- subset(menu.df, type == "task")

  output$messageMenu <- renderMenu({
    msgs <- apply(messageData, 1, function(row) {
      messageItem(from = row[["from"]], message = row[["message"]])
    })

    dropdownMenu(type = "messages", .list = msgs)

  })

  output$notificationMenu <- renderMenu({
    nots <- apply(notificationData, 1, function(row) {
      notificationItem(text = row[["message"]], status = row[["status"]])
    })
    dropdownMenu(type = "notifications", .list = nots)
  })

  output$taskMenu <- renderMenu({
    taks <- apply(taskData, 1, function(row) {
      taskItem(text = row[["message"]], color = row[["color"]], value = row[["value"]])
    })
    dropdownMenu(type = "tasks", .list = taks)
  })

  datasetInput <- reactive({
    switch(
      input$dataset,
      "rock" = rock,
      "pressure" = pressure,
      "cars" = cars
    )
  })

  output$view <- renderGvis({
    gvisScatterChart(dropDownMenus, options = list(width = 400, height = 450))

  })

  output$plot1 <- renderPlot({
    data <- histdata[seq_len(input$slider)]
    hist(data)
  })

  output$plot2 <- renderPlot({
    data <- histdata[seq_len(input$slider)]
    hist(data)
  })

  output$progressBox <- renderInfoBox({
    infoBox(
      "Progress", paste0(25 + input$count, "%"), icon = icon("list"),
      color = "purple"
    )
  })

  output$approvalBox <- renderInfoBox({
    infoBox(
      "Confidence", "80%", icon = icon("eye-open", lib = "glyphicon"),
      color = "yellow"
    )
  })

  # Same as above, but with fill=TRUE
  output$progressBox2 <- renderInfoBox({
    infoBox(
      "Managed Spend (mil)", paste0("USD ", 25 + input$count), icon = icon("dollar"),
      color = "purple", fill = TRUE
    )
  })
  output$approvalBox2 <- renderInfoBox({
    infoBox(
      "Model Performance", "80%", icon = icon("thumbs-up", lib = "glyphicon"),
      color = "green", fill = TRUE
    )
  })
}

shinyApp(ui, server)

from shinydashboard.

wch avatar wch commented on May 12, 2024

Great, glad you got it figured out!

from shinydashboard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.