Branches of mechanical engineering: Edifice Shiny App Exercises + Solutions - Business Office X - R




SHINY DASHBOARD STRUCTURE & APPEARANCE
Finally nosotros reached inwards the lastly part of our series. At this part nosotros volition encounter how to ameliorate the construction together with the appearance of our dashboard fifty-fifty more, according to our preferences together with of course of educational activity arrive to a greater extent than attractive to the user. Last but non to the lowest degree nosotros volition encounter the simplest together with easiest way to deploy it.
Read the examples below to sympathise the logic of what nosotros are going to do together with thence examine yous skills amongst the practise laid nosotros prepared for you. Lets begin!
Answers to the exercises are available here.
infoBox
There is a particular sort of box that is used for displaying uncomplicated numeric or text values, amongst an icon.The illustration code below shows how to generate infoBox. The commencement row of infoBox uses the default setting of fill=FALSE.
Since the content of an infoBox will ordinarily live dynamic, shinydashboard contains the helper functions infoBoxOutput and renderInfoBox for dynamic content.
#ui.R
library(shinydashboard)
dashboardPage(
dashboardHeader(title = "Info boxes"),
dashboardSidebar(),
dashboardBody(
# infoBoxes amongst fill=FALSE
fluidRow(
# Influenza A virus subtype H5N1 static infoBox
infoBox("New Orders", 10 * 2, icon = icon("credit-card")),
# Dynamic infoBoxes
infoBoxOutput("progressBox"),
infoBoxOutput("approvalBox")
)))

#server.R
shinyServer(function(input, output) {
output$progressBox <- renderInfoBox({
infoBox(
"Progress", paste0(25 + input$count, "%"), icon = icon("list"),
color = "purple"
)
})
output$approvalBox <- renderInfoBox({
infoBox(
"Approval", "80%", icon = icon("thumbs-up", lib = "glyphicon"),
color = "yellow"
)
})
})
Exercise 1
Create three infoBox with information icons together with color of your pick together with seat them inwards the tabItem “dt” nether the “DATA-TABLE”.
To fill upwards them amongst a color follow the illustration below:
#ui.R
library(shinydashboard)
dashboardPage(
dashboardHeader(title = "Info boxes"),
dashboardSidebar(),
dashboardBody(
# infoBoxes amongst fill=FALSE
fluidRow(
# Influenza A virus subtype H5N1 static infoBox
infoBox("New Orders", 10 * 2, icon = icon("credit-card"),fill = TRUE),
# Dynamic infoBoxes
infoBoxOutput("progressBox"),
infoBoxOutput("approvalBox")
)))
#server.R
shinyServer(function(input, output) {
output$progressBox <- renderInfoBox({
infoBox(
"Progress", paste0(25 + input$count, "%"), icon = icon("list"),
color = "purple",fill = TRUE
)
})
output$approvalBox <- renderInfoBox({
infoBox(
"Approval", "80%", icon = icon("thumbs-up", lib = "glyphicon"),
color = "yellow",fill = TRUE
)
})
})
Exercise 2
Fill the infoBox with the color you selected inwards Exercise 1. HINT: Use fill.
Exercise 3
Now heighten the appearance of your tabItem named “km” past times setting height = 450 inwards the four box you bring there.
Skins
There are a issue of color themes, or skins. The default is blue, but at that spot are also black, purple, green, red, together with yellow. You tin give the axe select which subject to usage with dashboardPage(skin = "blue")dashboardPage(skin = "black"), together with thence on.
Exercise 4
Change skin from bluish to red.
CSS
You tin give the axe add together custom CSS to your app past times adding code inwards the UI of your app similar this:
#ui.R
dashboardPage(
dashboardHeader(title = "Custom font"),
dashboardSidebar(),
dashboardBody(
tags$head(tags$style(HTML('
.main-header .logo {
font-family: "Georgia", Times, "Times New Roman", serif;
font-weight: bold;
font-size: 24px;
}
')))
)
)
Exercise 5
Change the font of your dashboard championship past times adding CSS code.
Long titles
In about cases, the championship that you lot wishing to usage won’t gibe inwards the default width inwards the header bar. You tin give the axe brand the infinite for the championship wider amongst the titleWidth option. In this example, we’ve increased the width for the championship to 450 pixels.
#ui.R
dashboardPage(
dashboardHeader(
title = "Example of a long championship that needs to a greater extent than space",
titleWidth = 450
),
dashboardSidebar(),
dashboardBody(
)
)

#server.R
function(input, output) { }
Exercise 6
Set your titlewidth to “400” together with thence laid it to the default value again.
Sidebar width
To alter the width of the sidebar, you lot tin give the axe usage the width option. This illustration has a wider championship together with sidebar:
#ui.R
library(shinydashboard)
dashboardPage(
dashboardHeader(
title = "Title together with sidebar 350 pixels wide",
titleWidth = 350
),
dashboardSidebar(
width = 350,
sidebarMenu(
menuItem("Menu Item")
)
),
dashboardBody()
)

#server.R
function(input, output) { }
Exercise 7
Set sidebar width to “400” together with thence homecoming to the default one.
Icons
Icons are used liberally in shinydashboard. The icons used in shiny and shinydashboard are actually simply characters from particular font sets, together with they’re created amongst Shiny’s icon() function.
To do a calendar icon, you’d call:
icon("calendar")
The icons are from Font-Awesome together with Glyphicons. You tin give the axe encounter lists of all available icons here:
Exercise 8
Change the icon of the three menuItem of your dashboard. Select whatever you lot similar from the 2 lists above.
Statuses together with colors
Many shinydashboard components bring a status or color argument.
The status is a belongings of about Bootstrap classes. It tin give the axe bring values like status="primary"status="success", together with others.
The color argument is to a greater extent than straightforward. It tin give the axe bring values like color="red"color="black", together with others.
The valid statuses together with colors are also listed in ?validStatusesand ?validColors.
Exercise 9
Change the status of the 3 widget box in the tabItem named “km” to “info”, “success” together with “danger” respectively.
Shinyapps.io
The easiest way to plough your Shiny app into a spider web page is to usage shinyapps.io, RStudio’s hosting service for Shiny apps.
shinyapps.io lets you lot upload your app right away from your R session to a server hosted past times RStudio. You bring consummate command over your app including server direction tools.
First of all you lot bring to do an concern human relationship in shinyapps.io.
Exercise 10

Publish your app through Shinyapps.io

____________________________________________

Below are the solutions to these exercises on Building Shiny App.
#################### #                  # #    Exercise 1    # #                  # ####################  #ui.r library(shiny) library(shinydashboard)  dashboardPage(   dashboardHeader(title = "Shiny App",                   dropdownMenu(type = "messages",                                messageItem(                                  from = "Bob Carter",                                  message = "Excellent dashboard.Keep the adept job"                                ),                                messageItem(                                  from = "New User",                                  message = "How do I register?",                                  icon = icon("question"),                                  time = "23:00"                                ),                                messageItem(                                  from = "Support",                                  message = "The novel server is ready.",                                  icon = icon("life-ring"),                                  time = "2017-15-03"                                )                   ),                   dropdownMenu(type = "notifications",                                notificationItem(                                  text = "5 novel users today",                                  icon("users")                                ),                                notificationItem(                                  text = "12 items delivered",                                  icon("truck"),                                  status = "success"                                ),                                notificationItem(                                  text = "Server charge at 86%",                                  icon = icon("exclamation-triangle"),                                  status = "warning"                                )                   ),                   dropdownMenu(type = "tasks", badgeStatus = "success",                                taskItem(value = 90, color = "green",                                         "Documentation"                                ),                                taskItem(value = 17, color = "aqua",                                         "Project Iris"                                ),                                taskItem(value = 75, color = "yellow",                                         "Server deployment"                                ),                                taskItem(value = 80, color = "red",                                         "Overall project"                                )                   )),   dashboardSidebar(     sidebarMenu(       menuItem("DATATABLE", tabName = "dt", icon = icon("dashboard")),       menuItem("SUMMARY", tabName = "sm", icon = icon("th")),       menuItem("K-MEANS", tabName = "km", icon = icon("th"))     )),   dashboardBody(     tabItems(       tabItem(tabName = "dt",               h2("DATA TABLE"),               fluidRow(                 box(title="DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table"),width = 400)               ),               # infoBoxes amongst fill=FALSE               fluidRow(                 # Influenza A virus subtype H5N1 static infoBox                 infoBox("New Orders", 15 * 2, icon = icon("credit-card")),                 # Dynamic infoBoxes                 infoBoxOutput("progressBox"),                 infoBoxOutput("approvalBox")               )),       tabItem(tabName = "sm",               h2("SUMMARY"),               fluidRow(                 box(title="SUMMARY DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table2"),width = 400)               )       ),       tabItem(tabName = "km",               fluidRow(                 box(title="K-MEANS",solidHeader = TRUE,status="primary",plotOutput("plot1",click = "mouse")),                 box(status="warning",sliderInput("slider1", label = h4("Clusters"),                                                  min = 1, max = 9, value = 4),                     verbatimTextOutput("coord"))),               fluidRow(                 box(status="warning",checkboxGroupInput("checkGroup",                                                         label = h4("Variable X"),names(iris),                                                         selected=names(iris)[[2]]                 )),                 box(status="warning",selectInput("select", label = h4("Variable Y"),                                                  names(iris),selected=names(iris)[[2]]                 )))       )     )   ) ) #server shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   sumiris<-as.data.frame.array(summary(iris))   output$Table2 <- renderDataTable(sumiris)   output$plot1 <- renderPlot({     palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",               "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))     plot(Data(),          col = Clusters()$cluster,          pch = 20, cex = 3,          cex.main = 2,   font.main= 4, col.main= "blue")   }, width = "auto",height = "auto")   output$coord <- renderText({     paste0("x=", input$mouse$x, "\ny=", input$mouse$y)   })     Data <- reactive({iris[, c(input$select,input$checkGroup)]   })   Clusters <- reactive({     kmeans(Data(),input$slider1)   })    output$progressBox <- renderInfoBox({     infoBox(       "Progress", paste0(25 + input$count, "%"), icon = icon("list"),       color = "red"     )   })   output$approvalBox <- renderInfoBox({     infoBox(       "Approval", "70%", icon = icon("thumbs-up", lib = "glyphicon"),       color = "green"     )   })  })  #################### #                  # #    Exercise 2    # #                  # ####################  #ui.r library(shiny) library(shinydashboard)  dashboardPage(   dashboardHeader(title = "Shiny App",                   dropdownMenu(type = "messages",                                messageItem(                                  from = "Bob Carter",                                  message = "Excellent dashboard.Keep the adept job"                                ),                                messageItem(                                  from = "New User",                                  message = "How do I register?",                                  icon = icon("question"),                                  time = "23:00"                                ),                                messageItem(                                  from = "Support",                                  message = "The novel server is ready.",                                  icon = icon("life-ring"),                                  time = "2017-15-03"                                )                   ),                   dropdownMenu(type = "notifications",                                notificationItem(                                  text = "5 novel users today",                                  icon("users")                                ),                                notificationItem(                                  text = "12 items delivered",                                  icon("truck"),                                  status = "success"                                ),                                notificationItem(                                  text = "Server charge at 86%",                                  icon = icon("exclamation-triangle"),                                  status = "warning"                                )                   ),                   dropdownMenu(type = "tasks", badgeStatus = "success",                                taskItem(value = 90, color = "green",                                         "Documentation"                                ),                                taskItem(value = 17, color = "aqua",                                         "Project Iris"                                ),                                taskItem(value = 75, color = "yellow",                                         "Server deployment"                                ),                                taskItem(value = 80, color = "red",                                         "Overall project"                                )                   )),   dashboardSidebar(     sidebarMenu(       menuItem("DATATABLE", tabName = "dt", icon = icon("dashboard")),       menuItem("SUMMARY", tabName = "sm", icon = icon("th")),       menuItem("K-MEANS", tabName = "km", icon = icon("th"))     )),   dashboardBody(     tabItems(       tabItem(tabName = "dt",               h2("DATA TABLE"),               fluidRow(                 box(title="DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table"),width = 400)               ),               # infoBoxes amongst fill=FALSE               fluidRow(                 # Influenza A virus subtype H5N1 static infoBox                 infoBox("New Orders", 15 * 2, icon = icon("credit-card"),fill = TRUE),                 # Dynamic infoBoxes                 infoBoxOutput("progressBox"),                 infoBoxOutput("approvalBox")               )),       tabItem(tabName = "sm",               h2("SUMMARY"),               fluidRow(                 box(title="SUMMARY DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table2"),width = 400)               )       ),       tabItem(tabName = "km",               fluidRow(                 box(title="K-MEANS",solidHeader = TRUE,status="primary",plotOutput("plot1",click = "mouse")),                 box(status="warning",sliderInput("slider1", label = h4("Clusters"),                                                  min = 1, max = 9, value = 4),                     verbatimTextOutput("coord"))),               fluidRow(                 box(status="warning",checkboxGroupInput("checkGroup",                                                         label = h4("Variable X"),names(iris),                                                         selected=names(iris)[[2]]                 )),                 box(status="warning",selectInput("select", label = h4("Variable Y"),                                                  names(iris),selected=names(iris)[[2]]                 )))       )     )   ) ) #server shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   sumiris<-as.data.frame.array(summary(iris))   output$Table2 <- renderDataTable(sumiris)   output$plot1 <- renderPlot({     palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",               "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))     plot(Data(),          col = Clusters()$cluster,          pch = 20, cex = 3,          cex.main = 2,   font.main= 4, col.main= "blue")   }, width = "auto",height = "auto")   output$coord <- renderText({     paste0("x=", input$mouse$x, "\ny=", input$mouse$y)   })     Data <- reactive({iris[, c(input$select,input$checkGroup)]   })   Clusters <- reactive({     kmeans(Data(),input$slider1)   })    output$progressBox <- renderInfoBox({     infoBox(       "Progress", paste0(25 + input$count, "%"), icon = icon("list"),       color = "red",fill = TRUE     )   })   output$approvalBox <- renderInfoBox({     infoBox(       "Approval", "70%", icon = icon("thumbs-up", lib = "glyphicon"),       color = "green",fill = TRUE     )   })  })  #################### #                  # #    Exercise 3    # #                  # ####################  #ui.r library(shiny) library(shinydashboard)  dashboardPage(   dashboardHeader(title = "Shiny App",                   dropdownMenu(type = "messages",                                messageItem(                                  from = "Bob Carter",                                  message = "Excellent dashboard.Keep the adept job"                                ),                                messageItem(                                  from = "New User",                                  message = "How do I register?",                                  icon = icon("question"),                                  time = "23:00"                                ),                                messageItem(                                  from = "Support",                                  message = "The novel server is ready.",                                  icon = icon("life-ring"),                                  time = "2017-15-03"                                )                   ),                   dropdownMenu(type = "notifications",                                notificationItem(                                  text = "5 novel users today",                                  icon("users")                                ),                                notificationItem(                                  text = "12 items delivered",                                  icon("truck"),                                  status = "success"                                ),                                notificationItem(                                  text = "Server charge at 86%",                                  icon = icon("exclamation-triangle"),                                  status = "warning"                                )                   ),                   dropdownMenu(type = "tasks", badgeStatus = "success",                                taskItem(value = 90, color = "green",                                         "Documentation"                                ),                                taskItem(value = 17, color = "aqua",                                         "Project Iris"                                ),                                taskItem(value = 75, color = "yellow",                                         "Server deployment"                                ),                                taskItem(value = 80, color = "red",                                         "Overall project"                                )                   )),   dashboardSidebar(     sidebarMenu(       menuItem("DATATABLE", tabName = "dt", icon = icon("dashboard")),       menuItem("SUMMARY", tabName = "sm", icon = icon("th")),       menuItem("K-MEANS", tabName = "km", icon = icon("th"))     )),   dashboardBody(     tabItems(       tabItem(tabName = "dt",               h2("DATA TABLE"),               fluidRow(                 box(title="DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table"),width = 400)               ),               # infoBoxes amongst fill=FALSE               fluidRow(                 # Influenza A virus subtype H5N1 static infoBox                 infoBox("New Orders", 15 * 2, icon = icon("credit-card"),fill = TRUE),                 # Dynamic infoBoxes                 infoBoxOutput("progressBox"),                 infoBoxOutput("approvalBox")               )),       tabItem(tabName = "sm",               h2("SUMMARY"),               fluidRow(                 box(title="SUMMARY DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table2"),width = 400)               )       ),       tabItem(tabName = "km",               fluidRow(                 box(title="K-MEANS",height=450,solidHeader = TRUE,status="primary",plotOutput("plot1",click = "mouse")),                 box(status="warning",height=450,sliderInput("slider1", label = h4("Clusters"),                                                  min = 1, max = 9, value = 4),                     verbatimTextOutput("coord"))),               fluidRow(                 box(status="warning",height=450,checkboxGroupInput("checkGroup",                                                         label = h4("Variable X"),names(iris),                                                         selected=names(iris)[[2]]                 )),                 box(status="warning",height=450,selectInput("select", label = h4("Variable Y"),                                                  names(iris),selected=names(iris)[[2]]                 )))       )     )   ) ) #server shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   sumiris<-as.data.frame.array(summary(iris))   output$Table2 <- renderDataTable(sumiris)   output$plot1 <- renderPlot({     palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",               "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))     plot(Data(),          col = Clusters()$cluster,          pch = 20, cex = 3,          cex.main = 2,   font.main= 4, col.main= "blue")   }, width = "auto",height = "auto")   output$coord <- renderText({     paste0("x=", input$mouse$x, "\ny=", input$mouse$y)   })     Data <- reactive({iris[, c(input$select,input$checkGroup)]   })   Clusters <- reactive({     kmeans(Data(),input$slider1)   })    output$progressBox <- renderInfoBox({     infoBox(       "Progress", paste0(25 + input$count, "%"), icon = icon("list"),       color = "red",fill = TRUE     )   })   output$approvalBox <- renderInfoBox({     infoBox(       "Approval", "70%", icon = icon("thumbs-up", lib = "glyphicon"),       color = "green",fill = TRUE     )   })  })  #################### #                  # #    Exercise 4    # #                  # ####################  #ui.r library(shiny) library(shinydashboard)  dashboardPage(skin = "red",   dashboardHeader(title = "Shiny App",                   dropdownMenu(type = "messages",                                messageItem(                                  from = "Bob Carter",                                  message = "Excellent dashboard.Keep the adept job"                                ),                                messageItem(                                  from = "New User",                                  message = "How do I register?",                                  icon = icon("question"),                                  time = "23:00"                                ),                                messageItem(                                  from = "Support",                                  message = "The novel server is ready.",                                  icon = icon("life-ring"),                                  time = "2017-15-03"                                )                   ),                   dropdownMenu(type = "notifications",                                notificationItem(                                  text = "5 novel users today",                                  icon("users")                                ),                                notificationItem(                                  text = "12 items delivered",                                  icon("truck"),                                  status = "success"                                ),                                notificationItem(                                  text = "Server charge at 86%",                                  icon = icon("exclamation-triangle"),                                  status = "warning"                                )                   ),                   dropdownMenu(type = "tasks", badgeStatus = "success",                                taskItem(value = 90, color = "green",                                         "Documentation"                                ),                                taskItem(value = 17, color = "aqua",                                         "Project Iris"                                ),                                taskItem(value = 75, color = "yellow",                                         "Server deployment"                                ),                                taskItem(value = 80, color = "red",                                         "Overall project"                                )                   )),   dashboardSidebar(     sidebarMenu(       menuItem("DATATABLE", tabName = "dt", icon = icon("dashboard")),       menuItem("SUMMARY", tabName = "sm", icon = icon("th")),       menuItem("K-MEANS", tabName = "km", icon = icon("th"))     )),   dashboardBody(     tabItems(       tabItem(tabName = "dt",               h2("DATA TABLE"),               fluidRow(                 box(title="DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table"),width = 400)               ),               # infoBoxes amongst fill=FALSE               fluidRow(                 # Influenza A virus subtype H5N1 static infoBox                 infoBox("New Orders", 15 * 2, icon = icon("credit-card"),fill = TRUE),                 # Dynamic infoBoxes                 infoBoxOutput("progressBox"),                 infoBoxOutput("approvalBox")               )),       tabItem(tabName = "sm",               h2("SUMMARY"),               fluidRow(                 box(title="SUMMARY DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table2"),width = 400)               )       ),       tabItem(tabName = "km",               fluidRow(                 box(title="K-MEANS",height=450,solidHeader = TRUE,status="primary",plotOutput("plot1",click = "mouse")),                 box(status="warning",height=450,sliderInput("slider1", label = h4("Clusters"),                                                  min = 1, max = 9, value = 4),                     verbatimTextOutput("coord"))),               fluidRow(                 box(status="warning",height=450,checkboxGroupInput("checkGroup",                                                         label = h4("Variable X"),names(iris),                                                         selected=names(iris)[[2]]                 )),                 box(status="warning",height=450,selectInput("select", label = h4("Variable Y"),                                                  names(iris),selected=names(iris)[[2]]                 )))       )     )   ) ) #server shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   sumiris<-as.data.frame.array(summary(iris))   output$Table2 <- renderDataTable(sumiris)   output$plot1 <- renderPlot({     palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",               "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))     plot(Data(),          col = Clusters()$cluster,          pch = 20, cex = 3,          cex.main = 2,   font.main= 4, col.main= "blue")   }, width = "auto",height = "auto")   output$coord <- renderText({     paste0("x=", input$mouse$x, "\ny=", input$mouse$y)   })     Data <- reactive({iris[, c(input$select,input$checkGroup)]   })   Clusters <- reactive({     kmeans(Data(),input$slider1)   })    output$progressBox <- renderInfoBox({     infoBox(       "Progress", paste0(25 + input$count, "%"), icon = icon("list"),       color = "red",fill = TRUE     )   })   output$approvalBox <- renderInfoBox({     infoBox(       "Approval", "70%", icon = icon("thumbs-up", lib = "glyphicon"),       color = "green",fill = TRUE     )   })  })  #################### #                  # #    Exercise five    # #                  # ####################  #ui.r library(shiny) library(shinydashboard)  dashboardPage(skin = "red",   dashboardHeader(title = "Shiny App",                   dropdownMenu(type = "messages",                                messageItem(                                  from = "Bob Carter",                                  message = "Excellent dashboard.Keep the adept job"                                ),                                messageItem(                                  from = "New User",                                  message = "How do I register?",                                  icon = icon("question"),                                  time = "23:00"                                ),                                messageItem(                                  from = "Support",                                  message = "The novel server is ready.",                                  icon = icon("life-ring"),                                  time = "2017-15-03"                                )                   ),                   dropdownMenu(type = "notifications",                                notificationItem(                                  text = "5 novel users today",                                  icon("users")                                ),                                notificationItem(                                  text = "12 items delivered",                                  icon("truck"),                                  status = "success"                                ),                                notificationItem(                                  text = "Server charge at 86%",                                  icon = icon("exclamation-triangle"),                                  status = "warning"                                )                   ),                   dropdownMenu(type = "tasks", badgeStatus = "success",                                taskItem(value = 90, color = "green",                                         "Documentation"                                ),                                taskItem(value = 17, color = "aqua",                                         "Project Iris"                                ),                                taskItem(value = 75, color = "yellow",                                         "Server deployment"                                ),                                taskItem(value = 80, color = "red",                                         "Overall project"                                )                   )),   dashboardSidebar(     sidebarMenu(       menuItem("DATATABLE", tabName = "dt", icon = icon("dashboard")),       menuItem("SUMMARY", tabName = "sm", icon = icon("th")),       menuItem("K-MEANS", tabName = "km", icon = icon("th"))     )),   dashboardBody(tags$head(tags$style(HTML('       .main-header .logo {                                           font-family: "Georgia", Times, "Times New Roman", serif;                                           font-weight: bold;                                           font-size: 24px;                                           }                                           '))),     tabItems(       tabItem(tabName = "dt",               h2("DATA TABLE"),               fluidRow(                 box(title="DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table"),width = 400)               ),               # infoBoxes amongst fill=FALSE               fluidRow(                 # Influenza A virus subtype H5N1 static infoBox                 infoBox("New Orders", 15 * 2, icon = icon("credit-card"),fill = TRUE),                 # Dynamic infoBoxes                 infoBoxOutput("progressBox"),                 infoBoxOutput("approvalBox")               )),       tabItem(tabName = "sm",               h2("SUMMARY"),               fluidRow(                 box(title="SUMMARY DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table2"),width = 400)               )       ),       tabItem(tabName = "km",               fluidRow(                 box(title="K-MEANS",height=450,solidHeader = TRUE,status="primary",plotOutput("plot1",click = "mouse")),                 box(status="warning",height=450,sliderInput("slider1", label = h4("Clusters"),                                                  min = 1, max = 9, value = 4),                     verbatimTextOutput("coord"))),               fluidRow(                 box(status="warning",height=450,checkboxGroupInput("checkGroup",                                                         label = h4("Variable X"),names(iris),                                                         selected=names(iris)[[2]]                 )),                 box(status="warning",height=450,selectInput("select", label = h4("Variable Y"),                                                  names(iris),selected=names(iris)[[2]]                 )))       )     )   ) ) #server shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   sumiris<-as.data.frame.array(summary(iris))   output$Table2 <- renderDataTable(sumiris)   output$plot1 <- renderPlot({     palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",               "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))     plot(Data(),          col = Clusters()$cluster,          pch = 20, cex = 3,          cex.main = 2,   font.main= 4, col.main= "blue")   }, width = "auto",height = "auto")   output$coord <- renderText({     paste0("x=", input$mouse$x, "\ny=", input$mouse$y)   })     Data <- reactive({iris[, c(input$select,input$checkGroup)]   })   Clusters <- reactive({     kmeans(Data(),input$slider1)   })    output$progressBox <- renderInfoBox({     infoBox(       "Progress", paste0(25 + input$count, "%"), icon = icon("list"),       color = "red",fill = TRUE     )   })   output$approvalBox <- renderInfoBox({     infoBox(       "Approval", "70%", icon = icon("thumbs-up", lib = "glyphicon"),       color = "green",fill = TRUE     )   })  })  #################### #                  # #    Exercise half-dozen    # #                  # ####################  #ui.r library(shiny) library(shinydashboard)  dashboardPage(skin = "red",   dashboardHeader(title = "Shiny App",                   titleWidth = "400",                   dropdownMenu(type = "messages",                                messageItem(                                  from = "Bob Carter",                                  message = "Excellent dashboard.Keep the adept job"                                ),                                messageItem(                                  from = "New User",                                  message = "How do I register?",                                  icon = icon("question"),                                  time = "23:00"                                ),                                messageItem(                                  from = "Support",                                  message = "The novel server is ready.",                                  icon = icon("life-ring"),                                  time = "2017-15-03"                                )                   ),                   dropdownMenu(type = "notifications",                                notificationItem(                                  text = "5 novel users today",                                  icon("users")                                ),                                notificationItem(                                  text = "12 items delivered",                                  icon("truck"),                                  status = "success"                                ),                                notificationItem(                                  text = "Server charge at 86%",                                  icon = icon("exclamation-triangle"),                                  status = "warning"                                )                   ),                   dropdownMenu(type = "tasks", badgeStatus = "success",                                taskItem(value = 90, color = "green",                                         "Documentation"                                ),                                taskItem(value = 17, color = "aqua",                                         "Project Iris"                                ),                                taskItem(value = 75, color = "yellow",                                         "Server deployment"                                ),                                taskItem(value = 80, color = "red",                                         "Overall project"                                )                   )),   dashboardSidebar(     sidebarMenu(       menuItem("DATATABLE", tabName = "dt", icon = icon("dashboard")),       menuItem("SUMMARY", tabName = "sm", icon = icon("th")),       menuItem("K-MEANS", tabName = "km", icon = icon("th"))     )),   dashboardBody(tags$head(tags$style(HTML('       .main-header .logo {                                           font-family: "Georgia", Times, "Times New Roman", serif;                                           font-weight: bold;                                           font-size: 24px;                                           }                                           '))),     tabItems(       tabItem(tabName = "dt",               h2("DATA TABLE"),               fluidRow(                 box(title="DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table"),width = 400)               ),               # infoBoxes amongst fill=FALSE               fluidRow(                 # Influenza A virus subtype H5N1 static infoBox                 infoBox("New Orders", 15 * 2, icon = icon("credit-card"),fill = TRUE),                 # Dynamic infoBoxes                 infoBoxOutput("progressBox"),                 infoBoxOutput("approvalBox")               )),       tabItem(tabName = "sm",               h2("SUMMARY"),               fluidRow(                 box(title="SUMMARY DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table2"),width = 400)               )       ),       tabItem(tabName = "km",               fluidRow(                 box(title="K-MEANS",height=450,solidHeader = TRUE,status="primary",plotOutput("plot1",click = "mouse")),                 box(status="warning",height=450,sliderInput("slider1", label = h4("Clusters"),                                                  min = 1, max = 9, value = 4),                     verbatimTextOutput("coord"))),               fluidRow(                 box(status="warning",height=450,checkboxGroupInput("checkGroup",                                                         label = h4("Variable X"),names(iris),                                                         selected=names(iris)[[2]]                 )),                 box(status="warning",height=450,selectInput("select", label = h4("Variable Y"),                                                  names(iris),selected=names(iris)[[2]]                 )))       )     )   ) ) #server shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   sumiris<-as.data.frame.array(summary(iris))   output$Table2 <- renderDataTable(sumiris)   output$plot1 <- renderPlot({     palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",               "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))     plot(Data(),          col = Clusters()$cluster,          pch = 20, cex = 3,          cex.main = 2,   font.main= 4, col.main= "blue")   }, width = "auto",height = "auto")   output$coord <- renderText({     paste0("x=", input$mouse$x, "\ny=", input$mouse$y)   })     Data <- reactive({iris[, c(input$select,input$checkGroup)]   })   Clusters <- reactive({     kmeans(Data(),input$slider1)   })    output$progressBox <- renderInfoBox({     infoBox(       "Progress", paste0(25 + input$count, "%"), icon = icon("list"),       color = "red",fill = TRUE     )   })   output$approvalBox <- renderInfoBox({     infoBox(       "Approval", "70%", icon = icon("thumbs-up", lib = "glyphicon"),       color = "green",fill = TRUE     )   })  })  #################### #                  # #    Exercise vii    # #                  # ####################  #ui.r library(shiny) library(shinydashboard)  dashboardPage(skin = "red",   dashboardHeader(title = "Shiny App",                   dropdownMenu(type = "messages",                                messageItem(                                  from = "Bob Carter",                                  message = "Excellent dashboard.Keep the adept job"                                ),                                messageItem(                                  from = "New User",                                  message = "How do I register?",                                  icon = icon("question"),                                  time = "23:00"                                ),                                messageItem(                                  from = "Support",                                  message = "The novel server is ready.",                                  icon = icon("life-ring"),                                  time = "2017-15-03"                                )                   ),                   dropdownMenu(type = "notifications",                                notificationItem(                                  text = "5 novel users today",                                  icon("users")                                ),                                notificationItem(                                  text = "12 items delivered",                                  icon("truck"),                                  status = "success"                                ),                                notificationItem(                                  text = "Server charge at 86%",                                  icon = icon("exclamation-triangle"),                                  status = "warning"                                )                   ),                   dropdownMenu(type = "tasks", badgeStatus = "success",                                taskItem(value = 90, color = "green",                                         "Documentation"                                ),                                taskItem(value = 17, color = "aqua",                                         "Project Iris"                                ),                                taskItem(value = 75, color = "yellow",                                         "Server deployment"                                ),                                taskItem(value = 80, color = "red",                                         "Overall project"                                )                   )),   dashboardSidebar(     width=400,     sidebarMenu(       menuItem("DATATABLE", tabName = "dt", icon = icon("dashboard")),       menuItem("SUMMARY", tabName = "sm", icon = icon("th")),       menuItem("K-MEANS", tabName = "km", icon = icon("th"))     )),   dashboardBody(tags$head(tags$style(HTML('       .main-header .logo {                                           font-family: "Georgia", Times, "Times New Roman", serif;                                           font-weight: bold;                                           font-size: 24px;                                           }                                           '))),     tabItems(       tabItem(tabName = "dt",               h2("DATA TABLE"),               fluidRow(                 box(title="DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table"),width = 400)               ),               # infoBoxes amongst fill=FALSE               fluidRow(                 # Influenza A virus subtype H5N1 static infoBox                 infoBox("New Orders", 15 * 2, icon = icon("credit-card"),fill = TRUE),                 # Dynamic infoBoxes                 infoBoxOutput("progressBox"),                 infoBoxOutput("approvalBox")               )),       tabItem(tabName = "sm",               h2("SUMMARY"),               fluidRow(                 box(title="SUMMARY DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table2"),width = 400)               )       ),       tabItem(tabName = "km",               fluidRow(                 box(title="K-MEANS",height=450,solidHeader = TRUE,status="primary",plotOutput("plot1",click = "mouse")),                 box(status="warning",height=450,sliderInput("slider1", label = h4("Clusters"),                                                  min = 1, max = 9, value = 4),                     verbatimTextOutput("coord"))),               fluidRow(                 box(status="warning",height=450,checkboxGroupInput("checkGroup",                                                         label = h4("Variable X"),names(iris),                                                         selected=names(iris)[[2]]                 )),                 box(status="warning",height=450,selectInput("select", label = h4("Variable Y"),                                                  names(iris),selected=names(iris)[[2]]                 )))       )     )   ) ) #server shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   sumiris<-as.data.frame.array(summary(iris))   output$Table2 <- renderDataTable(sumiris)   output$plot1 <- renderPlot({     palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",               "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))     plot(Data(),          col = Clusters()$cluster,          pch = 20, cex = 3,          cex.main = 2,   font.main= 4, col.main= "blue")   }, width = "auto",height = "auto")   output$coord <- renderText({     paste0("x=", input$mouse$x, "\ny=", input$mouse$y)   })     Data <- reactive({iris[, c(input$select,input$checkGroup)]   })   Clusters <- reactive({     kmeans(Data(),input$slider1)   })    output$progressBox <- renderInfoBox({     infoBox(       "Progress", paste0(25 + input$count, "%"), icon = icon("list"),       color = "red",fill = TRUE     )   })   output$approvalBox <- renderInfoBox({     infoBox(       "Approval", "70%", icon = icon("thumbs-up", lib = "glyphicon"),       color = "green",fill = TRUE     )   })  })  #################### #                  # #    Exercise 8    # #                  # ####################  #ui.r library(shiny) library(shinydashboard)  dashboardPage(skin = "red",   dashboardHeader(title = "Shiny App",                   dropdownMenu(type = "messages",                                messageItem(                                  from = "Bob Carter",                                  message = "Excellent dashboard.Keep the adept job"                                ),                                messageItem(                                  from = "New User",                                  message = "How do I register?",                                  icon = icon("question"),                                  time = "23:00"                                ),                                messageItem(                                  from = "Support",                                  message = "The novel server is ready.",                                  icon = icon("life-ring"),                                  time = "2017-15-03"                                )                   ),                   dropdownMenu(type = "notifications",                                notificationItem(                                  text = "5 novel users today",                                  icon("users")                                ),                                notificationItem(                                  text = "12 items delivered",                                  icon("truck"),                                  status = "success"                                ),                                notificationItem(                                  text = "Server charge at 86%",                                  icon = icon("exclamation-triangle"),                                  status = "warning"                                )                   ),                   dropdownMenu(type = "tasks", badgeStatus = "success",                                taskItem(value = 90, color = "green",                                         "Documentation"                                ),                                taskItem(value = 17, color = "aqua",                                         "Project Iris"                                ),                                taskItem(value = 75, color = "yellow",                                         "Server deployment"                                ),                                taskItem(value = 80, color = "red",                                         "Overall project"                                )                   )),   dashboardSidebar(     width=400,     sidebarMenu(       menuItem("DATATABLE", tabName = "dt", icon = icon("dashboard")),       menuItem("SUMMARY", tabName = "sm", icon = icon("id-card-o")),       menuItem("K-MEANS", tabName = "km", icon = icon("vcard-o"))     )),   dashboardBody(tags$head(tags$style(HTML('       .main-header .logo {                                           font-family: "Georgia", Times, "Times New Roman", serif;                                           font-weight: bold;                                           font-size: 24px;                                           }                                           '))),     tabItems(       tabItem(tabName = "dt",               h2("DATA TABLE"),               fluidRow(                 box(title="DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table"),width = 400)               ),               # infoBoxes amongst fill=FALSE               fluidRow(                 # Influenza A virus subtype H5N1 static infoBox                 infoBox("New Orders", 15 * 2, icon = icon("credit-card"),fill = TRUE),                 # Dynamic infoBoxes                 infoBoxOutput("progressBox"),                 infoBoxOutput("approvalBox")               )),       tabItem(tabName = "sm",               h2("SUMMARY"),               fluidRow(                 box(title="SUMMARY DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table2"),width = 400)               )       ),       tabItem(tabName = "km",               fluidRow(                 box(title="K-MEANS",height=450,solidHeader = TRUE,status="primary",plotOutput("plot1",click = "mouse")),                 box(status="warning",height=450,sliderInput("slider1", label = h4("Clusters"),                                                  min = 1, max = 9, value = 4),                     verbatimTextOutput("coord"))),               fluidRow(                 box(status="warning",height=450,checkboxGroupInput("checkGroup",                                                         label = h4("Variable X"),names(iris),                                                         selected=names(iris)[[2]]                 )),                 box(status="warning",height=450,selectInput("select", label = h4("Variable Y"),                                                  names(iris),selected=names(iris)[[2]]                 )))       )     )   ) ) #server shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   sumiris<-as.data.frame.array(summary(iris))   output$Table2 <- renderDataTable(sumiris)   output$plot1 <- renderPlot({     palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",               "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))     plot(Data(),          col = Clusters()$cluster,          pch = 20, cex = 3,          cex.main = 2,   font.main= 4, col.main= "blue")   }, width = "auto",height = "auto")   output$coord <- renderText({     paste0("x=", input$mouse$x, "\ny=", input$mouse$y)   })     Data <- reactive({iris[, c(input$select,input$checkGroup)]   })   Clusters <- reactive({     kmeans(Data(),input$slider1)   })    output$progressBox <- renderInfoBox({     infoBox(       "Progress", paste0(25 + input$count, "%"), icon = icon("list"),       color = "red",fill = TRUE     )   })   output$approvalBox <- renderInfoBox({     infoBox(       "Approval", "70%", icon = icon("thumbs-up", lib = "glyphicon"),       color = "green",fill = TRUE     )   })  })  #################### #                  # #    Exercise nine    # #                  # ####################  #ui.r library(shiny) library(shinydashboard)  dashboardPage(skin = "red",   dashboardHeader(title = "Shiny App",                   dropdownMenu(type = "messages",                                messageItem(                                  from = "Bob Carter",                                  message = "Excellent dashboard.Keep the adept job"                                ),                                messageItem(                                  from = "New User",                                  message = "How do I register?",                                  icon = icon("question"),                                  time = "23:00"                                ),                                messageItem(                                  from = "Support",                                  message = "The novel server is ready.",                                  icon = icon("life-ring"),                                  time = "2017-15-03"                                )                   ),                   dropdownMenu(type = "notifications",                                notificationItem(                                  text = "5 novel users today",                                  icon("users")                                ),                                notificationItem(                                  text = "12 items delivered",                                  icon("truck"),                                  status = "success"                                ),                                notificationItem(                                  text = "Server charge at 86%",                                  icon = icon("exclamation-triangle"),                                  status = "warning"                                )                   ),                   dropdownMenu(type = "tasks", badgeStatus = "success",                                taskItem(value = 90, color = "green",                                         "Documentation"                                ),                                taskItem(value = 17, color = "aqua",                                         "Project Iris"                                ),                                taskItem(value = 75, color = "yellow",                                         "Server deployment"                                ),                                taskItem(value = 80, color = "red",                                         "Overall project"                                )                   )),   dashboardSidebar(     width=400,     sidebarMenu(       menuItem("DATATABLE", tabName = "dt", icon = icon("dashboard")),       menuItem("SUMMARY", tabName = "sm", icon = icon("id-card-o")),       menuItem("K-MEANS", tabName = "km", icon = icon("vcard-o"))     )),   dashboardBody(tags$head(tags$style(HTML('       .main-header .logo {                                           font-family: "Georgia", Times, "Times New Roman", serif;                                           font-weight: bold;                                           font-size: 24px;                                           }                                           '))),     tabItems(       tabItem(tabName = "dt",               h2("DATA TABLE"),               fluidRow(                 box(title="DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table"),width = 400)               ),               # infoBoxes amongst fill=FALSE               fluidRow(                 # Influenza A virus subtype H5N1 static infoBox                 infoBox("New Orders", 15 * 2, icon = icon("credit-card"),fill = TRUE),                 # Dynamic infoBoxes                 infoBoxOutput("progressBox"),                 infoBoxOutput("approvalBox")               )),       tabItem(tabName = "sm",               h2("SUMMARY"),               fluidRow(                 box(title="SUMMARY DATA TABLE",solidHeader = TRUE,status="primary",dataTableOutput("Table2"),width = 400)               )       ),       tabItem(tabName = "km",               fluidRow(                 box(title="K-MEANS",height=450,solidHeader = TRUE,status="primary",plotOutput("plot1",click = "mouse")),                 box(status="info",height=450,sliderInput("slider1", label = h4("Clusters"),                                                  min = 1, max = 9, value = 4),                     verbatimTextOutput("coord"))),               fluidRow(                 box(status="success",height=450,checkboxGroupInput("checkGroup",                                                         label = h4("Variable X"),names(iris),                                                         selected=names(iris)[[2]]                 )),                 box(status="danger",height=450,selectInput("select", label = h4("Variable Y"),                                                  names(iris),selected=names(iris)[[2]]                 )))       )     )   ) ) #server shinyServer(function(input, output) {   output$Table <- renderDataTable(     iris,options = list(       lengthMenu = list(c(10, 20, 30,-1),c('10','20','30','ALL')),       pageLength = 10))   sumiris<-as.data.frame.array(summary(iris))   output$Table2 <- renderDataTable(sumiris)   output$plot1 <- renderPlot({     palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",               "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))     plot(Data(),          col = Clusters()$cluster,          pch = 20, cex = 3,          cex.main = 2,   font.main= 4, col.main= "blue")   }, width = "auto",height = "auto")   output$coord <- renderText({     paste0("x=", input$mouse$x, "\ny=", input$mouse$y)   })     Data <- reactive({iris[, c(input$select,input$checkGroup)]   })   Clusters <- reactive({     kmeans(Data(),input$slider1)   })    output$progressBox <- renderInfoBox({     infoBox(       "Progress", paste0(25 + input$count, "%"), icon = icon("list"),       color = "red",fill = TRUE     )   })   output$approvalBox <- renderInfoBox({     infoBox(       "Approval", "70%", icon = icon("thumbs-up", lib = "glyphicon"),       color = "green",fill = TRUE     )   })  })  #################### #                  # #    Exercise 10   # #                  # ####################  # 1.Run your app. # 2.Press the "Publish" push clitoris inwards the correct upper corner of your app. # 3.Check the files of your working directory that you lot desire to live published inwards "Publish Files from:".It is prophylactic to banking concern check them all. # 4.From "Destination Account" select your concern human relationship inwards shinyapps.io. # 5.Give a championship of your choise inwards the "Title" window. # 6.Press "Publish". # 7.Log inwards to your concern human relationship inwards shinyapps.io. Account -> Tokens -> Show -> Copy to clipboard. Then glue this primal together with that's all! 


http://www.r-exercises.com/2017/04/11/building-shiny-app-solutions-part-10/
http://www.r-exercises.com/2017/04/11/building-shiny-app-exercises-part-10/

Sumber http://engdashboard.blogspot.com/

Jangan sampai ketinggalan postingan-postingan terbaik dari Branches of mechanical engineering: Edifice Shiny App Exercises + Solutions - Business Office X - R. Berlangganan melalui email sekarang juga:

Bali Attractions

BACA JUGA LAINNYA:

Bali Attractions