Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## ui.R ##
- library(shinydashboard)
- dashboardPage(
- dashboardHeader(),
- dashboardSidebar(),
- dashboardBody()
- )
- ## app.R ##
- library(shiny)
- library(shinydashboard)
- library(bubbles)
- library(dplyr)
- library(sunburstR)
- library(rvest)
- library(stringr)
- library(tidyr)
- library(networkD3)
- library(TraMineR)
- library(sunburstR)
- library(pipeR)
- # Define UI
- ui <- dashboardPage(skin="blue",
- dashboardHeader(title = tags$a(href='http://sailpoint.com',
- tags$img(src='sailpoint-logo-wh.png', height=35, width=135))),
- ## Sidebar content
- dashboardSidebar(
- sidebarMenu(
- menuItem("Bubble plot", tabName = "bubble", icon = icon("group")),
- menuItem("Sunburst plot", tabName = "sunburst", icon = icon("sun-o")),
- menuItem("Sankey plot", tabName = "plot", icon = icon("tasks"))
- )
- ),
- ## Body content
- dashboardBody(
- tabItems(
- # First tab content
- tabItem(tabName = "bubble",
- fluidRow(
- box(
- width = 12, status = "info", solidHeader = TRUE,
- title = "Peer groups by size",
- bubblesOutput("bubble", width = "100%", height = 600)
- #plotOutput("bubble_plot", width = "100%", height = 600)
- )
- ),
- fluidRow(
- column(
- width = 12,
- offset = 4,
- box(
- width = 4, status = "warning", solidHeader = TRUE,
- height = 200,
- title = "Number of clusters",
- sliderInput("slider_bubble", "", 2, 20, 1)
- )
- )
- )
- ),
- # Second tab content
- tabItem(tabName = "sunburst",
- fluidRow(
- box(
- width = 12, status = "info", solidHeader = TRUE,
- title = "School-to-work transition in Northern Ireland",
- sunburstOutput("sunburst", width = "100%", height = 800)
- )
- )
- ),
- # Third tab content
- tabItem(tabName = "plot",
- fluidRow(
- box(
- width = 12,
- status = "info", solidHeader = TRUE,
- title = "Energy consumption",
- plotOutput("plot", width = "100%", height = 800)
- )
- )
- )
- )
- )
- )
- # Server logic
- server <- function(input, output, session){
- # output$input <- renderUI({})
- # outputOptions(output, "input", suspendWhenHidden = FALSE)
- # Bubble plot
- output$bubble <- renderBubbles({
- bubbles(value = sqrt(exp(seq(0, as.integer(input$slider_bubble) - 1, by=1))),
- label = letters[1:as.integer(input$slider_bubble)],
- color = paste0("#", lapply(1:as.integer(input$slider_bubble), function(i) paste0(sample(c(0:9,toupper(letters[1:6])), 6 , replace = T),collapse = ''))) %>% unlist())
- })
- # Sunburst plot
- output$sunburst <- renderSunburst({
- # use example from TraMineR vignette
- # data("mvad")
- # mvad.alphab <- c(
- # "employment", "FE", "HE", "joblessness",
- # "school", "training"
- # )
- # mvad.seq <- seqdef(mvad, 17:86, xtstep = 6, alphabet = mvad.alphab)
- #
- # # to make this work, we'll compress the sequences with seqdss
- # # could also aggregate with dply later
- # seqtab( seqdss(mvad.seq), tlim = 0, format = "SPS" ) %>>%
- # attr("freq") %>>%
- # (
- # data.frame(
- # # appending "-end" is necessary for this to work
- # sequence = paste0(
- # gsub(
- # x = names(.$Freq)
- # , pattern = "(/[0-9]*)"
- # , replacement = ""
- # , perl = T
- # )
- # ,"-end"
- # )
- # ,freq = as.numeric(.$Freq)
- # ,stringsAsFactors = FALSE
- # )
- # ) %>>%
- sunburst(readRDS("/Users/mohamed.badawy/projects/IAI_exploration/Shiny/sunburst_df.rds"))
- })
- # Sankey plot
- output$sankey <- renderSankeyNetwork({
- # Load energy projection data
- URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json"
- Energy <- jsonlite::fromJSON(URL)
- # Now we have 2 data frames: a 'links' data frame with 3 columns (from, to, value), and a 'nodes' data frame that gives the name of each node.
- #head( Energy$links )
- #head( Energy$nodes )
- # Thus we can plot it
- sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
- Target = "target", Value = "value", NodeID = "name",
- units = "TWh", fontSize = 12, nodeWidth = 30)
- })
- # test plot
- output$plot <- renderPlot({hist(rnorm(1000))})
- }
- shinyApp(ui, server)
- ## app.R ##
- library(shiny)
- library(shinydashboard)
- library(bubbles)
- library(dplyr)
- library(sunburstR)
- library(rvest)
- library(stringr)
- library(tidyr)
- library(networkD3)
- library(TraMineR)
- library(sunburstR)
- library(pipeR)
- # Define UI
- ui <- dashboardPage(skin="blue",
- dashboardHeader(title = tags$a(href='http://sailpoint.com',
- tags$img(src='sailpoint-logo-wh.png', height=35, width=135))),
- ## Sidebar content
- dashboardSidebar(
- sidebarMenu(
- menuItem("Bubble plot", tabName = "bubble", icon = icon("group")),
- menuItem("Sunburst plot", tabName = "sunburst", icon = icon("sun-o")),
- menuItem("Sankey plot", tabName = "sankey", icon = icon("tasks"))
- )
- ),
- ## Body content
- dashboardBody(
- tabItems(
- # First tab content
- tabItem(tabName = "bubble",
- fluidRow(
- box(
- width = 12, status = "info", solidHeader = TRUE,
- title = "Peer groups by size",
- bubblesOutput("bubble", width = "100%", height = 600)
- #plotOutput("bubble_plot", width = "100%", height = 600)
- )
- ),
- fluidRow(
- column(
- width = 12,
- offset = 4,
- box(
- width = 4, status = "warning", solidHeader = TRUE,
- height = 200,
- title = "Number of clusters",
- sliderInput("slider_bubble", "", 2, 20, 1)
- )
- )
- )
- ),
- # Second tab content
- tabItem(tabName = "sunburst",
- fluidRow(
- box(
- width = 12, status = "info", solidHeader = TRUE,
- title = "School-to-work transition in Northern Ireland",
- sunburstOutput("sunburst", width = "100%", height = 800)
- )
- )
- ),
- # Third tab content
- tabItem(tabName = "sankey",
- fluidRow(
- box(
- width = 12,
- status = "info", solidHeader = TRUE,
- title = "Energy consumption",
- sankeyNetworkOutput("sankey", width = "100%", height = 800)
- )
- )
- )
- )
- )
- )
- # Server logic
- server <- function(input, output, session){
- # output$input <- renderUI({})
- # outputOptions(output, "input", suspendWhenHidden = FALSE)
- # Bubble plot
- output$bubble <- renderBubbles({
- bubbles(value = sqrt(exp(seq(0, as.integer(input$slider_bubble) - 1, by=1))),
- label = letters[1:as.integer(input$slider_bubble)],
- color = paste0("#", lapply(1:as.integer(input$slider_bubble), function(i) paste0(sample(c(0:9,toupper(letters[1:6])), 6 , replace = T),collapse = ''))) %>% unlist())
- })
- # Sunburst plot
- output$sunburst <- renderSunburst({
- # use example from TraMineR vignette
- # data("mvad")
- # mvad.alphab <- c(
- # "employment", "FE", "HE", "joblessness",
- # "school", "training"
- # )
- # mvad.seq <- seqdef(mvad, 17:86, xtstep = 6, alphabet = mvad.alphab)
- #
- # # to make this work, we'll compress the sequences with seqdss
- # # could also aggregate with dply later
- # seqtab( seqdss(mvad.seq), tlim = 0, format = "SPS" ) %>>%
- # attr("freq") %>>%
- # (
- # data.frame(
- # # appending "-end" is necessary for this to work
- # sequence = paste0(
- # gsub(
- # x = names(.$Freq)
- # , pattern = "(/[0-9]*)"
- # , replacement = ""
- # , perl = T
- # )
- # ,"-end"
- # )
- # ,freq = as.numeric(.$Freq)
- # ,stringsAsFactors = FALSE
- # )
- # ) %>>%
- sunburst(readRDS("/Users/mohamed.badawy/projects/IAI_exploration/Shiny/sunburst_df.rds"))
- })
- # Sankey plot
- output$sankey <- renderSankeyNetwork({
- # Load energy projection data
- URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json"
- Energy <- jsonlite::fromJSON(URL)
- # Now we have 2 data frames: a 'links' data frame with 3 columns (from, to, value), and a 'nodes' data frame that gives the name of each node.
- #head( Energy$links )
- #head( Energy$nodes )
- # Thus we can plot it
- sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
- Target = "target", Value = "value", NodeID = "name",
- units = "TWh", fontSize = 12, nodeWidth = 30)
- })
- }
- shinyApp(ui, server)
Add Comment
Please, Sign In to add comment