0% found this document useful (0 votes)
59 views3 pages

DV Lab Ex - No.8

The document describes creating a sales dashboard using Shiny in R. It loads necessary libraries and sales data, defines the UI with a header, sidebar and body. The body includes value boxes showing total sales and units sold. Plots in the body show revenue by sales rep and region over quarters. The server code generates the value box and plot outputs from the sales data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views3 pages

DV Lab Ex - No.8

The document describes creating a sales dashboard using Shiny in R. It loads necessary libraries and sales data, defines the UI with a header, sidebar and body. The body includes value boxes showing total sales and units sold. Plots in the body show revenue by sales rep and region over quarters. The server code generates the value box and plot outputs from the sales data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

22CS307PC- DATA VISUALIZATION LAB

Ex. No.: 8 Date: 27/11/2023

LAB PROBLEM:
Creating Dashboards and Storytelling, creating your first dashboard and Story, Design for different displays,
adding interactivity to your Dashboard, Distributing and Publishing your Visualization.

AIM: To create Sales Dashboard using Shiny.

PROGRAM:
library(shiny)
require(shinydashboard)
library(ggplot2)
library(dplyr)

df <- read.csv ('d:/R_PRG/csv/Sales_Sample.csv', stringsAsFactors = F, header=T)

header <- dashboardHeader(title = "Dashboard")

sidebar <- dashboardSidebar(sidebarMenu(menuItem("Sales Dashboard", tabName = "dashboard", icon =


icon("dashboard"))))

frow1 <- fluidRow(valueBoxOutput("value1"),valueBoxOutput("value2"))

frow2 <- fluidRow(box(title = "Revenue by Sales Rep", status = "primary", solidHeader = TRUE,
collapsible = TRUE, plotOutput("revenuebyRep", height = "300px")),
box (title = "Regionwise Sales Data",status = "primary", solidHeader = TRUE,
collapsible = TRUE, plotOutput("revenuebyRegion", height = "300px")))

# Combine the two fluid rows to make the body


body <- dashboardBody(frow1, frow2)

#completing the ui part with dashboard Page


ui <- dashboardPage(title = 'Sales Dashboard', header, sidebar, body, skin='red')

# Create the server functions for the dashboard


server <- function (input, output) {

#Some data manipulation to derive the values of KPI boxes


total.sales <- sum(df$Sales)
total.units <- sum(df$Units_Sold)

output$value1 <- renderValueBox({ valueBox(formatC(total.sales, format="d", big.mark=','),


'Total Sales',icon = icon("stats",lib='glyphicon'),color = "purple")})

output$value2 <- renderValueBox({ valueBox(formatC(total.units, format="d", big.mark=','),


'Total Units Sold',icon = icon("gbp",lib='glyphicon'),color = "green")})
22CS307PC- DATA VISUALIZATION LAB

#creating the plot Output content


output$revenuebyRep <- renderPlot({
ggplot(data = df, aes(x=QTR, y=Sales, fill=factor(SalesRep))) +
geom_bar(position = "dodge", stat = "identity") +
ylab("Sales in Rupees") + xlab("Querter") +
theme (legend.position="bottom", plot.title = element_text(size=15, face="bold")) +
ggtitle("Revenue by Sales Rep") + labs(fill = "Sales Rep")})

output$revenuebyRegion <- renderPlot({


ggplot(data = df, aes(x=QTR, y=Sales, fill=factor(Region))) +
geom_bar(position = "dodge", stat = "identity") +
ylab("Sales in Rupees") + xlab("Querter") +
theme (legend.position="bottom",plot.title = element_text(size=15, face="bold")) +
ggtitle("Regionwise Revenue") + labs(fill = "Region")})
}
shinyApp(ui, server)

INPUT: Sales_Sample.csv
SalesRep, Region, QTR, Sales, Units_Sold
Amy, North, Q1,24971,84
Amy, South, Q2,25749,557
Amy, East, Q3,24437,95
Amy, West, Q4,25355,706
Bob, North, Q1,25320,231
Bob, South, Q2,25999,84
Bob, East, Q3,22639,260
Bob, West, Q4,23949,109
Chuck, North, Q1,20280,453
Chuck, South, Q2,21584,114
Chuck, East, Q3,19625,83
Chuck, West, Q4,19832,70
Doug, North, Q1,25150,242
Doug, South, Q2,29061,146
Doug, East, Q3,27113,120
Doug, West, Q4,25953,81
John, North, Q1,34971,184
John, South, Q2,35749,657
John, East, Q3,34437,295
John, West, Q4,35355,806
22CS307PC- DATA VISUALIZATION LAB

OUTPUT:

RESULT: The above experiment is successfully executed and output is verified.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy