Bearloga has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311156

Change subject: Add bookmarking states
......................................................................

Add bookmarking states

In Shiny 0.14, RStudio added a way to bookmark
the state of the dashboard. Previously, we've
used the shinyURL R package, but this way we
use something that is now built into Shiny.

Bug: T145478
Change-Id: I32f0565a86500c3a702ad54cd06b87bf6059a2f4
---
M functions.R
A global.R
M prince.Rproj
M server.R
M ui.R
M www/custom.js
6 files changed, 238 insertions(+), 236 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/discovery/prince 
refs/changes/56/311156/1

diff --git a/functions.R b/functions.R
index 3674885..7ee1f65 100644
--- a/functions.R
+++ b/functions.R
@@ -7,27 +7,27 @@
 
 # Read in the traffic data
 read_clickthrough <- function(){
-  
+
   # Read in and format the high-level data
   data <- as.data.table(polloi::read_dataset(path = 
"portal/clickthrough_rate.tsv"))
-  clickthrough_rate <<- data[, j = list(success_rate = (events[type == 
"clickthrough"]/sum(events))*100), by = "date"]
-  
+  clickthrough_rate <<- data[, j = list(`clickthrough rate` = (events[type == 
"clickthrough"]/sum(events))*100), by = "date"]
+
   # Read in and format the breakdown data
   data <- as.data.table(polloi::read_dataset(path = 
"portal/clickthrough_breakdown.tsv"))
   data <- data[, j = list(section_used = section_used, proportion = 
(events/sum(events))*100), by = "date"]
   action_breakdown <<- reshape2::dcast(data, formula = date ~ section_used, 
fun.aggregate = sum)
-  
+
   # Read in most common section per visit data
   data <- as.data.table(polloi::read_dataset(path = 
"portal/most_common_per_visit.tsv"))
   data <- data[, j = list(section_used = section_used, proportion = 
(visits/sum(visits))*100), by = "date"]
   most_common <<- reshape2::dcast(data, formula = date ~ section_used, 
fun.aggregate = sum)
-  
+
   # Read in first visit clickthrough rates
   data <- polloi::read_dataset(path = "portal/clickthrough_firstvisit.tsv")
   data[, -1] <- data[, -1]*100 # first column is always going to be the date
   data$`language search` <- 0
   first_visit_ctrs <<- as.data.frame(data[, names(action_breakdown)])
-  
+
   return(invisible())
 }
 
@@ -42,7 +42,7 @@
 
 read_country <- function(){
   data <- as.data.table(polloi::read_dataset(path = "portal/country_data.tsv"))
-  
+
   country_data <<- reshape2::dcast(data[,list(country = country, events = 
round(events/sum(events)*100,2)),
                                         by = "date"],
                                    formula = date ~ country, fun.aggregate = 
sum)
@@ -88,15 +88,15 @@
 }
 
 read_referrals <- function(){
-  
+
   # Read in the initial data
   data <- as.data.table(polloi::read_dataset(path = 
"portal/portal_referer_data.tsv"))
-  
+
   # Format
   data$is_search <- ifelse(data$is_search, "Referred by search", "Not referred 
by search")
   data$search_engine[data$search_engine == "none"] <- "Not referred by search"
-  
-  
+
+
   # Write out the overall values for traffic
   interim <- data[, j = list(pageviews = sum(pageviews)),
                     by = c("date", "referer_class")] %>%
@@ -117,16 +117,16 @@
                       "Unknown referers",
                       "Total")
   summary_traffic_data <<- interim[, 1:7]
-  
+
   # Generate per-engine values
   interim <- data[data$search_engine != "Not referred by search",
                   j = list(pageviews = sum(pageviews)),
                   by = c("date", "search_engine")] %>%
     reshape2::dcast(formula = date ~ search_engine, fun.aggregate = sum)
   bysearch_traffic_data <<- cbind(date = interim$date, 
data.frame(round(100*t(apply(interim[, -1], 1, function(x) { x/sum(x) })), 2)))
-  
+
   return(invisible())
-  
+
 }
 
 fill_out <- function(x, start_date, end_date, fill = 0) {
diff --git a/global.R b/global.R
new file mode 100644
index 0000000..6300d25
--- /dev/null
+++ b/global.R
@@ -0,0 +1 @@
+enableBookmarking(store = "url")
diff --git a/prince.Rproj b/prince.Rproj
index a213108..e83436a 100644
--- a/prince.Rproj
+++ b/prince.Rproj
@@ -13,3 +13,4 @@
 LaTeX: pdfLaTeX
 
 AutoAppendNewline: Yes
+StripTrailingWhitespace: Yes
diff --git a/server.R b/server.R
index 51a3264..3e50149 100644
--- a/server.R
+++ b/server.R
@@ -1,16 +1,14 @@
 library(shiny)
 library(shinydashboard)
 library(dygraphs)
-library(shinyURL)
 library(shinyjs)
 
 source("functions.R")
-options(scipen = 500)
 
 existing_date <- Sys.Date() - 1
 
 shinyServer(function(input, output, session) {
-  
+
   if (Sys.Date() != existing_date) {
     progress <- shiny::Progress$new(session, min = 0, max = 1)
     on.exit(progress$close())
@@ -31,14 +29,12 @@
     progress$set(message = "Finished downloading datasets.", value = 1)
     existing_date <<- Sys.Date()
   }
-  
-  shinyURL.server(session)
-  
+
   output$clickthrough_rate_dygraph <- renderDygraph({
     clickthrough_rate %>%
       polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, 
input$smoothing_clickthrough_rate)) %>%
       polloi::make_dygraph(xlab = "Date", ylab = "Clickthrough rate (%)",
-                           title = "Wikipedia portal clickthrough rate") %>%
+                           title = "Wikipedia.org Portal Clickthrough Rate") 
%>%
       dyCSS(css = "www/inverse.css") %>%
       dyAxis("x", axisLabelFormatter = polloi::custom_axis_formatter, 
axisLabelWidth = 70) %>%
       dyLegend(labelsDiv = "clickthrough_rate_legend", show = "always") %>%
@@ -49,7 +45,7 @@
       dyEvent(as.Date("2016-06-02"), "Detect Language Deployed", labelLoc = 
"bottom", color = "white") %>%
       dyEvent(as.Date("2016-08-16"), "Secondary Links Collapsed", labelLoc = 
"bottom", color = "white")
   })
-  
+
   output$action_breakdown_dygraph <- renderDygraph({
     action_breakdown %>%
       polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, 
input$smoothing_action_breakdown)) %>%
@@ -65,7 +61,7 @@
       dyEvent(as.Date("2016-06-02"), "Detect Language Deployed", labelLoc = 
"bottom", color = "white") %>%
       dyEvent(as.Date("2016-08-16"), "Secondary Links Collapsed", labelLoc = 
"bottom", color = "white")
   })
-  
+
   output$most_common_dygraph <- renderDygraph({
     most_common %>%
       polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_most_common)) %>%
@@ -79,7 +75,7 @@
       dyEvent(as.Date("2016-06-02"), "Detect Language Deployed", labelLoc = 
"bottom", color = "white") %>%
       dyEvent(as.Date("2016-08-16"), "Secondary Links Collapsed", labelLoc = 
"bottom", color = "white")
   })
-  
+
   output$first_visit_dygraph <- renderDygraph({
     first_visit_ctrs %>%
       polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_first_visit)) %>%
@@ -94,7 +90,7 @@
       dyEvent(as.Date("2016-06-02"), "Detect Language Deployed", labelLoc = 
"bottom", color = "white") %>%
       dyEvent(as.Date("2016-08-16"), "Secondary Links Collapsed", labelLoc = 
"bottom", color = "white")
   })
-  
+
   output$dwelltime_dygraph <- renderDygraph({
     dwelltime_data %>%
       polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_dwelltime)) %>%
@@ -109,7 +105,7 @@
       dyEvent(as.Date("2016-06-02"), "Detect Language Deployed", labelLoc = 
"bottom", color = "white") %>%
       dyEvent(as.Date("2016-08-16"), "Secondary Links Collapsed", labelLoc = 
"bottom", color = "white")
   })
-  
+
   output$country_breakdown_dygraph <- renderDygraph({
     if (input$group_us_regions) {
       temp <- country_data
@@ -142,7 +138,7 @@
       dyEvent(as.Date("2016-06-28"), "A (regional U.S.)", labelLoc = "bottom", 
color = "white") %>%
       dyEvent(as.Date("2016-08-16"), "Secondary Links Collapsed", labelLoc = 
"bottom", color = "white")
   })
-  
+
   output$browser_selector_container <- renderUI({
     browsers <- switch(input$browser_order,
                        "alphabet" = {
@@ -219,7 +215,7 @@
     return(selectInput("browser_selector", "Browser", selected = selected, 
choices = browsers,
                        multiple = TRUE, selectize = FALSE, size = 15))
   })
-  
+
   output$browser_breakdown_dygraph <- renderDygraph({
     if (input$group_browsers) {
       if (input$browser_grouping == "family") {
@@ -250,7 +246,7 @@
       dyEvent(as.Date("2016-06-02"), "Detect Language Deployed", labelLoc = 
"bottom", color = "white") %>%
       dyEvent(as.Date("2016-08-16"), "Secondary Links Collapsed", labelLoc = 
"bottom", color = "white")
   })
-  
+
   output$pageview_dygraph <- renderDygraph({
     pageview_data %>%
       polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_pageviews)) %>%
@@ -268,7 +264,7 @@
       dyEvent(as.Date("2016-07-11"), "D (split-pageviews)", labelLoc = 
"bottom", color = "white") %>%
       dyEvent(as.Date("2016-08-16"), "Secondary Links Collapsed", labelLoc = 
"bottom", color = "white")
   })
-  
+
   output$referer_summary_dygraph <- renderDygraph({
     summary_traffic_data %>%
       polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_referer_summary)) 
%>%
@@ -282,7 +278,7 @@
       dyEvent(as.Date("2016-03-07"), "A (UDF switch)", labelLoc = "bottom", 
color = "white") %>%
       dyEvent(as.Date("2016-05-01"), "B (search-redirect.php)", labelLoc = 
"bottom", color = "white")
   })
-  
+
   output$search_engines_dygraph <- renderDygraph({
     bysearch_traffic_data %>%
       polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_search_engines)) 
%>%
@@ -294,15 +290,15 @@
       dyLegend(labelsDiv = "search_engines_legend", show = "always") %>%
       dyRangeSelector(fillColor = "", strokeColor = "", retainDateWindow = 
TRUE)
   })
-  
+
   output$s_dygraph <- renderDygraph({
-    
+
     if (!input$s_enwiki) {
       idx <- langs_visited$prefix != "en"
     } else {
       idx <- TRUE
     }
-    
+
     if (input$s_response == "clicks") {
       if (input$s_type == "count") {
         data4dygraph <- langs_visited[idx,
@@ -353,9 +349,9 @@
       dyEvent(as.Date("2016-06-02"), "Detect Language Deployed", labelLoc = 
"bottom", color = "white") %>%
       dyEvent(as.Date("2016-08-16"), "Secondary Links Collapsed", labelLoc = 
"bottom", color = "white")
   })
-  
+
   lv_reactive <- reactiveValues(choices = NULL, selected_langs = NULL)
-  
+
   observeEvent(input$lv_sort, {
     if (input$lv_sort %in% c("alphabet_az", "alphabet_za")) {
       lv_reactive$choices <- sort(unique(langs_visited$language), decreasing = 
input$lv_sort == "alphabet_za")
@@ -409,11 +405,11 @@
       }
     }
   })
-  
+
   observeEvent(input$lv_languages, {
     lv_reactive$selected_langs <- input$lv_languages
   })
-  
+
   output$lv_languages_container <- renderUI({
     if (input$lv_sort %in% c("top10", "bottom50")) {
       hidden(disabled(selectizeInput("lv_languages", "Wikipedia languages", 
lv_reactive$choices, lv_reactive$selected_langs, multiple = TRUE)))
@@ -421,21 +417,21 @@
       selectizeInput("lv_languages", "Wikipedia languages (12 max)", 
lv_reactive$choices, lv_reactive$selected_langs, multiple = TRUE, options = 
list(maxItems = 12))
     }
   })
-  
+
   observeEvent(input$lv_sort, {
-    
+
     # Make legend small in case of Top 10 or Bottom 50, otherwise make it big:
     toggleClass("lv_legend", "small", input$lv_sort %in% c("top10", 
"bottom50"))
     toggleClass("lv_legend", "large", !input$lv_sort %in% c("top10", 
"bottom50"))
-    
+
     if (input$lv_sort == "bottom50") {
       updateCheckboxInput(session, "lv_combine", value = TRUE)
     } else {
       updateCheckboxInput(session, "lv_combine", value = FALSE)
     }
-    
+
   })
-  
+
   output$lv_dygraph <- renderDygraph({
     if (input$lv_response == "clicks") {
       if (length(input$lv_languages) > 1) {
@@ -501,5 +497,5 @@
       dyEvent(as.Date("2016-06-02"), "Detect Language Deployed", labelLoc = 
"bottom", color = "white") %>%
       dyEvent(as.Date("2016-08-16"), "Secondary Links Collapsed", labelLoc = 
"bottom", color = "white")
   })
-  
+
 })
diff --git a/ui.R b/ui.R
index 8637109..711a2aa 100644
--- a/ui.R
+++ b/ui.R
@@ -1,201 +1,200 @@
 library(shiny)
 library(shinydashboard)
 library(dygraphs)
-library(shinyURL)
-options(scipen = 500)
 
-#Header elements for the visualisation
-header <- dashboardHeader(title = "Wikipedia.org Portal", disable = FALSE)
+function(request) {
+  dashboardPage(
 
-sidebar <- dashboardSidebar(
-  shinyjs::useShinyjs(),
-  tags$head(
-    tags$link(rel = "stylesheet", type = "text/css", href = "stylesheet.css"),
-    tags$script(src = "custom.js")
-  ),
-  sidebarMenu(menuItem("Engagement",
-                       menuSubItem(text = "Clickthrough rate", tabName = 
"clickthrough_rate"),
-                       menuSubItem(text = "Last action", tabName = 
"action_breakdown"),
-                       menuSubItem(text = "Most common section", tabName = 
"most_common"),
-                       menuSubItem(text = "First visit", tabName = 
"first_visit"),
-                       menuSubItem(text = "Dwell time", tabName = 
"dwell_data"),
-                       icon = icon("hand-o-up")),
-              menuItem("Traffic",
-                       menuSubItem(text = "Geographic breakdown", tabName = 
"country_breakdown"),
-                       menuSubItem(text = "Browser breakdown", tabName = 
"browser_breakdown"),
-                       menuSubItem(text = "Pageviews", tabName = 
"pageview_tab"),
-                       icon = icon("line-chart")),
-              menuItem("Languages",
-                       menuSubItem(text = "Summary", tabName = 
"languages_summary"),
-                       menuSubItem(text = "Languages visited", tabName = 
"languages_visited"),
-                       icon = icon("globe", lib = "glyphicon")),
-              menuItem("External Referrals",
-                       menuSubItem(text = "Overall Referral Traffic", tabName 
= "referrals_summary"),
-                       menuSubItem(text = "Breakdown by Search Engine", 
tabName = "search_engines"),
-                       icon = icon("external-link")),
-              menuItem(text = "Global Settings",
-                       selectInput(inputId = "smoothing_global", label = 
"Smoothing", selectize = TRUE, selected = "day",
-                                   choices = c("No Smoothing" = "day", "Weekly 
Median" = "week", "Monthly Median" = "month", "Splines" = "gam")),
-                       br(style = "line-height:25%;"), icon = icon("cog", lib 
= "glyphicon")),
-              menuItem(text = "Sharing Options", shinyURL.ui(tinyURL = FALSE),
-                       p("Dashboard settings stored in URL.", style = 
"padding-bottom: 10px;"),
-                       icon = icon("share-alt", lib = "glyphicon"))
-  ),
-  div(icon("info-sign", lib = "glyphicon"), HTML("<strong>Tip</strong>: you 
can drag on the graphs with your mouse to zoom in on a particular date 
range."), style = "padding: 10px; color: black;")
-)
+    dashboardHeader(title = "Wikipedia.org Portal", disable = FALSE),
 
-body <- dashboardBody(
-  tabItems(
-    tabItem(tabName = "clickthrough_rate",
-            fluidRow(
-              column(polloi::smooth_select("smoothing_clickthrough_rate"), 
width = 3),
-              column(div(id = "clickthrough_rate_legend", class = "dy-legend 
large"), width = 9)
-            ),
-            dygraphOutput("clickthrough_rate_dygraph"),
-            includeMarkdown("./tab_documentation/clickthrough_rate.md")
-    ),
-    tabItem(tabName = "action_breakdown",
-            fluidRow(
-              column(polloi::smooth_select("smoothing_action_breakdown"), 
width = 3),
-              column(div(id = "action_breakdown_legend", class = "dy-legend 
large"), width = 9)
-            ),
-            dygraphOutput("action_breakdown_dygraph"),
-            includeMarkdown("./tab_documentation/action_breakdown.md")
-    ),
-    tabItem(tabName = "most_common",
-            fluidRow(
-              column(polloi::smooth_select("smoothing_most_common"), width = 
3),
-              column(div(id = "most_common_legend", class = "dy-legend 
large"), width = 9)
-            ),
-            dygraphOutput("most_common_dygraph"),
-            includeMarkdown("./tab_documentation/most_common.md")
-    ),
-    tabItem(tabName = "first_visit",
-            fluidRow(
-              column(polloi::smooth_select("smoothing_first_visit"), width = 
3),
-              column(div(id = "first_visit_legend", class = "dy-legend 
large"), width = 9)
-            ),
-            dygraphOutput("first_visit_dygraph"),
-            includeMarkdown("./tab_documentation/first_visit.md")
-    ),
-    tabItem(tabName = "dwell_data",
-            fluidRow(
-              column(polloi::smooth_select("smoothing_dwelltime"), width = 3),
-              column(div(id = "dwelltime_legend", class = "dy-legend large"), 
width = 9)
-            ),
-            dygraphOutput("dwelltime_dygraph"),
-            includeMarkdown("./tab_documentation/dwelltime.md")
-    ),
-    tabItem(tabName = "country_breakdown",
-            
fluidRow(column(polloi::smooth_select("smoothing_country_breakdown"), width = 
4),
-                     column(checkboxInput("group_us_regions", "Group U.S. 
regions", value = FALSE), width = 2),
-                     column(checkboxInput("hide_less_than_5", "Hide countries 
with <5% traffic share", value = FALSE), width = 2),
-                     column(checkboxInput("hide_more_than_15", "Hide countries 
with >15% traffic share", value = FALSE), width = 2)),
-            div(dygraphOutput("country_breakdown_dygraph"),
-                div(id = "country_breakdown_legend",
-                    style = "height: 60px; padding-top: 30px; padding-left: 
20px;"),
-                style = "width: 100%; background-color: #222D32; color: 
#ECF0F5; padding-top: 10px;"),
-            includeMarkdown("./tab_documentation/geography.md")
-    ),
-    tabItem(tabName = "browser_breakdown",
-            fluidRow(column(selectInput("browser_order", "Sort", selected = 
"growth",
-                                        choices = list("Alphabetically" = 
"alphabet",
-                                                       "By popularity growth 
rate" = "growth",
-                                                       "By popularity decay 
rate" = "decay",
-                                                       "Last recorded 
percentage" = "last",
-                                                       "Number of times it 
appears in data" = "times")),
-                            textInput("browser_filter", "Filter", placeholder 
= "IE, firefox"),
-                            helpText("Case insensitive & accepts 
comma-separated input."),
-                            checkboxInput("group_browsers", "Group browser 
versions", FALSE),
-                            conditionalPanel("input.group_browsers",
-                                             radioButtons("browser_grouping", 
"Group by", inline = TRUE,
-                                                          choices = 
list("Browser Family" = "family",
-                                                                         
"MediaWiki Support" = "support"))),
-                            uiOutput("browser_selector_container"),
-                            width = 3),
-                     column(
-                       
div(polloi::smooth_select("smoothing_browser_breakdown"),
-                                dygraphOutput("browser_breakdown_dygraph"),
-                                div(id = "browser_breakdown_legend", class = 
"large",
-                                    style = "padding: 30px 0 10px 20px;"),
-                                style = "width: 100%; background-color: 
#222D32; color: #ECF0F5; padding-top: 10px;"),
-                            width = 9)),
-            includeMarkdown("./tab_documentation/browsers.md")
-    ),
-    tabItem(tabName = "pageview_tab",
-            fluidRow(
-              column(polloi::smooth_select("smoothing_pageviews"), width = 3),
-              column(HTML("<label style = \"margin-bottom: 
-10px;\">Scale</label>"),
-                     checkboxInput("pageview_logscale", "Use Log scale", 
FALSE),
-                     width = 4),
-              column(div(id = "pageview_legend", class = "dy-legend large"), 
width = 5)
-            ),
-            dygraphOutput("pageview_dygraph"),
-            includeMarkdown("./tab_documentation/pageviews.md")
-    ),
-    tabItem(tabName = "referrals_summary",
-            
fluidRow(column(polloi::smooth_select("smoothing_referer_summary"), width = 3),
-                     column(div(id = "referer_summary_legend", class = 
"dy-legend"), width = 9)),
-            dygraphOutput("referer_summary_dygraph"),
-            includeMarkdown("./tab_documentation/referers_summary.md")
-    ),
-    tabItem(tabName = "search_engines",
-            fluidRow(column(polloi::smooth_select("smoothing_search_engines"), 
width = 3),
-                     column(div(id = "search_engines_legend", class = 
"dy-legend large"), width = 9)),
-            dygraphOutput("search_engines_dygraph"),
-            includeMarkdown("./tab_documentation/referers_byengine.md")
-    ),
-    tabItem(
-      tabName = "languages_summary",
-      fluidRow(
-        column(polloi::smooth_select("smoothing_summary"), width = 3),
-        column(radioButtons("s_response", "Data", list("Clicks" = "clicks", 
"Users" = "users"), inline = TRUE), width = 2),
-        column(HTML("<label class = \"control-label\" style = 
\"margin-bottom:-30px;\">Filter</label>"),
-               checkboxInput("s_enwiki", "Include English Wikipedia", TRUE), 
width = 3),
-        column(conditionalPanel("input.s_response === 'clicks'", 
radioButtons("s_type", "Type", list("Counts" = "count", "Proportions" = 
"prop"), inline = TRUE)), width = 2),
-        column(conditionalPanel("input.s_response === 'clicks' & input.s_type 
=== 'count'",
-                                HTML("<label class = \"control-label\" style = 
\"margin-bottom:-30px;\">Scale</label>"),
-                                checkboxInput("s_logscale", "Use Log scale", 
FALSE)), width = 2)
+    dashboardSidebar(
+      shinyjs::useShinyjs(),
+      tags$head(
+        tags$link(rel = "stylesheet", type = "text/css", href = 
"stylesheet.css"),
+        tags$script(src = "custom.js")
       ),
-      dygraphOutput("s_dygraph"),
-      div(id = "s_legend", class = "large", style = "text-align: center; 
padding: 0 10px;"),
-      includeMarkdown("tab_documentation/languages_summary.md")
-    ),
-    tabItem(
-      tabName = "languages_visited",
-      fluidRow(
-        column(polloi::smooth_select("smoothing_lv"), width = 2),
-        column(radioButtons("lv_response", "Data", list("Clicks" = "clicks", 
"Users" = "users"), inline = TRUE), width = 2),
-        column(selectInput("lv_sort", "Sort languages",
-                           list("Top 10" = "top10",
-                                "Bottom 50" = "bottom50",
-                                "Overall Clicks (High to Low)" = 
"clicks_high2low",
-                                "Overall Clicks (Low to High)" = 
"clicks_low2high",
-                                "Daily Clicks (High to Low)" = 
"avg_clicks_high2low",
-                                "Daily Clicks (Low to High)" = 
"avg_clicks_low2high",
-                                "Alphabetically (A-Z)" = "alphabet_az",
-                                "Alphabetically (Z-A)" = "alphabet_za"),
-                           "top10"),
-               width = 3),
-        column(
-          uiOutput("lv_languages_container", style = "width: 80%; display: 
inline-block; float: left;",
-                   title = "Type to find a language. Use backspace key to 
remove a selected language. Up to 12 languages can be selected at the same 
time."),
-                   div(icon("question-circle", class = "fa-lg"),
-                       title = "Type to find a language. Use backspace key to 
remove a selected language.",
-                       style="width: 12.5%; margin-left: 2.5%; padding-top: 
30px; height: 34px; display: inline-block; float: left;"),
-          width = 3),
-        column(
-          conditionalPanel("input.lv_response === 'clicks' & 
input.lv_languages.length > 1 & input.lv_sort != 'top10'", HTML("<label class = 
\"control-label\" style = \"margin-bottom:-30px;\">Aggregation</label>"), 
checkboxInput("lv_combine", "Combine languages", FALSE)),
-          conditionalPanel("input.lv_response === 'clicks' & 
input.lv_languages.length < 2", radioButtons("lv_type", "Type", list("Counts" = 
"count", "Proportions" = "prop"), inline = TRUE)),
-          conditionalPanel("input.lv_type === 'count'", HTML("<label class = 
\"control-label\" style = \"margin-bottom:-30px;\">Scale</label>"), 
checkboxInput("lv_logscale", "Use Log scale", FALSE)),
-          width = 2)
+      sidebarMenu(id = "tabs",
+                  menuItem("Engagement",
+                           menuSubItem(text = "Clickthrough rate", tabName = 
"clickthrough_rate"),
+                           menuSubItem(text = "Last action", tabName = 
"action_breakdown"),
+                           menuSubItem(text = "Most common section", tabName = 
"most_common"),
+                           menuSubItem(text = "First visit", tabName = 
"first_visit"),
+                           menuSubItem(text = "Dwell time", tabName = 
"dwell_data"),
+                           icon = icon("hand-o-up")),
+                  menuItem("Traffic",
+                           menuSubItem(text = "Geographic breakdown", tabName 
= "country_breakdown"),
+                           menuSubItem(text = "Browser breakdown", tabName = 
"browser_breakdown"),
+                           menuSubItem(text = "Pageviews", tabName = 
"pageview_tab"),
+                           icon = icon("line-chart")),
+                  menuItem("Languages",
+                           menuSubItem(text = "Summary", tabName = 
"languages_summary"),
+                           menuSubItem(text = "Languages visited", tabName = 
"languages_visited"),
+                           icon = icon("globe", lib = "glyphicon")),
+                  menuItem("External Referrals",
+                           menuSubItem(text = "Overall Referral Traffic", 
tabName = "referrals_summary"),
+                           menuSubItem(text = "Breakdown by Search Engine", 
tabName = "search_engines"),
+                           icon = icon("external-link")),
+                  menuItem(text = "Global Settings",
+                           selectInput(inputId = "smoothing_global", label = 
"Smoothing", selectize = TRUE, selected = "day",
+                                       choices = c("No Smoothing" = "day", 
"Weekly Median" = "week", "Monthly Median" = "month", "Splines" = "gam")),
+                           br(style = "line-height:25%;"), icon = icon("cog", 
lib = "glyphicon"))
       ),
-      dygraphOutput("lv_dygraph"),
-      div(id = "lv_legend", class = "large", style = "text-align: center; 
padding: 15px 10px 0 10px;"),
-      includeMarkdown("tab_documentation/languages_visited.md")
-    )
-  )
-)
+      div(icon("info-sign", lib = "glyphicon"), HTML("<strong>Tip</strong>: 
you can drag on the graphs with your mouse to zoom in on a particular date 
range."), style = "padding: 10px; color: black;"),
+      div(bookmarkButton(), style = "text-align: center;")
+    ),
 
-dashboardPage(header, sidebar, body, skin = "black",
-              title = "Portal Traffic Dashboard | Discovery | Engineering | 
Wikimedia Foundation")
+    dashboardBody(
+      tabItems(
+        tabItem(tabName = "clickthrough_rate",
+                fluidRow(
+                  column(polloi::smooth_select("smoothing_clickthrough_rate"), 
width = 3),
+                  column(div(id = "clickthrough_rate_legend", class = 
"dy-legend large"), width = 9)
+                ),
+                dygraphOutput("clickthrough_rate_dygraph"),
+                includeMarkdown("./tab_documentation/clickthrough_rate.md")
+        ),
+        tabItem(tabName = "action_breakdown",
+                fluidRow(
+                  column(polloi::smooth_select("smoothing_action_breakdown"), 
width = 3),
+                  column(div(id = "action_breakdown_legend", class = 
"dy-legend large"), width = 9)
+                ),
+                dygraphOutput("action_breakdown_dygraph"),
+                includeMarkdown("./tab_documentation/action_breakdown.md")
+        ),
+        tabItem(tabName = "most_common",
+                fluidRow(
+                  column(polloi::smooth_select("smoothing_most_common"), width 
= 3),
+                  column(div(id = "most_common_legend", class = "dy-legend 
large"), width = 9)
+                ),
+                dygraphOutput("most_common_dygraph"),
+                includeMarkdown("./tab_documentation/most_common.md")
+        ),
+        tabItem(tabName = "first_visit",
+                fluidRow(
+                  column(polloi::smooth_select("smoothing_first_visit"), width 
= 3),
+                  column(div(id = "first_visit_legend", class = "dy-legend 
large"), width = 9)
+                ),
+                dygraphOutput("first_visit_dygraph"),
+                includeMarkdown("./tab_documentation/first_visit.md")
+        ),
+        tabItem(tabName = "dwell_data",
+                fluidRow(
+                  column(polloi::smooth_select("smoothing_dwelltime"), width = 
3),
+                  column(div(id = "dwelltime_legend", class = "dy-legend 
large"), width = 9)
+                ),
+                dygraphOutput("dwelltime_dygraph"),
+                includeMarkdown("./tab_documentation/dwelltime.md")
+        ),
+        tabItem(tabName = "country_breakdown",
+                
fluidRow(column(polloi::smooth_select("smoothing_country_breakdown"), width = 
4),
+                         column(checkboxInput("group_us_regions", "Group U.S. 
regions", value = FALSE), width = 2),
+                         column(checkboxInput("hide_less_than_5", "Hide 
countries with <5% traffic share", value = FALSE), width = 2),
+                         column(checkboxInput("hide_more_than_15", "Hide 
countries with >15% traffic share", value = FALSE), width = 2)),
+                div(dygraphOutput("country_breakdown_dygraph"),
+                    div(id = "country_breakdown_legend",
+                        style = "height: 60px; padding-top: 30px; 
padding-left: 20px;"),
+                    style = "width: 100%; background-color: #222D32; color: 
#ECF0F5; padding-top: 10px;"),
+                includeMarkdown("./tab_documentation/geography.md")
+        ),
+        tabItem(tabName = "browser_breakdown",
+                fluidRow(column(selectInput("browser_order", "Sort", selected 
= "growth",
+                                            choices = list("Alphabetically" = 
"alphabet",
+                                                           "By popularity 
growth rate" = "growth",
+                                                           "By popularity 
decay rate" = "decay",
+                                                           "Last recorded 
percentage" = "last",
+                                                           "Number of times it 
appears in data" = "times")),
+                                textInput("browser_filter", "Filter", 
placeholder = "IE, firefox"),
+                                helpText("Case insensitive & accepts 
comma-separated input."),
+                                checkboxInput("group_browsers", "Group browser 
versions", FALSE),
+                                conditionalPanel("input.group_browsers",
+                                                 
radioButtons("browser_grouping", "Group by", inline = TRUE,
+                                                              choices = 
list("Browser Family" = "family",
+                                                                             
"MediaWiki Support" = "support"))),
+                                uiOutput("browser_selector_container"),
+                                width = 3),
+                         column(
+                           
div(polloi::smooth_select("smoothing_browser_breakdown"),
+                               dygraphOutput("browser_breakdown_dygraph"),
+                               div(id = "browser_breakdown_legend", class = 
"large",
+                                   style = "padding: 30px 0 10px 20px;"),
+                               style = "width: 100%; background-color: 
#222D32; color: #ECF0F5; padding-top: 10px;"),
+                           width = 9)),
+                includeMarkdown("./tab_documentation/browsers.md")
+        ),
+        tabItem(tabName = "pageview_tab",
+                fluidRow(
+                  column(polloi::smooth_select("smoothing_pageviews"), width = 
3),
+                  column(HTML("<label style = \"margin-bottom: 
-10px;\">Scale</label>"),
+                         checkboxInput("pageview_logscale", "Use Log scale", 
FALSE),
+                         width = 4),
+                  column(div(id = "pageview_legend", class = "dy-legend 
large"), width = 5)
+                ),
+                dygraphOutput("pageview_dygraph"),
+                includeMarkdown("./tab_documentation/pageviews.md")
+        ),
+        tabItem(tabName = "referrals_summary",
+                
fluidRow(column(polloi::smooth_select("smoothing_referer_summary"), width = 3),
+                         column(div(id = "referer_summary_legend", class = 
"dy-legend"), width = 9)),
+                dygraphOutput("referer_summary_dygraph"),
+                includeMarkdown("./tab_documentation/referers_summary.md")
+        ),
+        tabItem(tabName = "search_engines",
+                
fluidRow(column(polloi::smooth_select("smoothing_search_engines"), width = 3),
+                         column(div(id = "search_engines_legend", class = 
"dy-legend large"), width = 9)),
+                dygraphOutput("search_engines_dygraph"),
+                includeMarkdown("./tab_documentation/referers_byengine.md")
+        ),
+        tabItem(
+          tabName = "languages_summary",
+          fluidRow(
+            column(polloi::smooth_select("smoothing_summary"), width = 3),
+            column(radioButtons("s_response", "Data", list("Clicks" = 
"clicks", "Users" = "users"), inline = TRUE), width = 2),
+            column(HTML("<label class = \"control-label\" style = 
\"margin-bottom:-30px;\">Filter</label>"),
+                   checkboxInput("s_enwiki", "Include English Wikipedia", 
TRUE), width = 3),
+            column(conditionalPanel("input.s_response === 'clicks'", 
radioButtons("s_type", "Type", list("Counts" = "count", "Proportions" = 
"prop"), inline = TRUE)), width = 2),
+            column(conditionalPanel("input.s_response === 'clicks' & 
input.s_type === 'count'",
+                                    HTML("<label class = \"control-label\" 
style = \"margin-bottom:-30px;\">Scale</label>"),
+                                    checkboxInput("s_logscale", "Use Log 
scale", FALSE)), width = 2)
+          ),
+          dygraphOutput("s_dygraph"),
+          div(id = "s_legend", class = "large", style = "text-align: center; 
padding: 0 10px;"),
+          includeMarkdown("tab_documentation/languages_summary.md")
+        ),
+        tabItem(
+          tabName = "languages_visited",
+          fluidRow(
+            column(polloi::smooth_select("smoothing_lv"), width = 2),
+            column(radioButtons("lv_response", "Data", list("Clicks" = 
"clicks", "Users" = "users"), inline = TRUE), width = 2),
+            column(selectInput("lv_sort", "Sort languages",
+                               list("Top 10" = "top10",
+                                    "Bottom 50" = "bottom50",
+                                    "Overall Clicks (High to Low)" = 
"clicks_high2low",
+                                    "Overall Clicks (Low to High)" = 
"clicks_low2high",
+                                    "Daily Clicks (High to Low)" = 
"avg_clicks_high2low",
+                                    "Daily Clicks (Low to High)" = 
"avg_clicks_low2high",
+                                    "Alphabetically (A-Z)" = "alphabet_az",
+                                    "Alphabetically (Z-A)" = "alphabet_za"),
+                               "top10"),
+                   width = 3),
+            column(
+              uiOutput("lv_languages_container", style = "width: 80%; display: 
inline-block; float: left;",
+                       title = "Type to find a language. Use backspace key to 
remove a selected language. Up to 12 languages can be selected at the same 
time."),
+              div(icon("question-circle", class = "fa-lg"),
+                  title = "Type to find a language. Use backspace key to 
remove a selected language.",
+                  style="width: 12.5%; margin-left: 2.5%; padding-top: 30px; 
height: 34px; display: inline-block; float: left;"),
+              width = 3),
+            column(
+              conditionalPanel("input.lv_response === 'clicks' & 
input.lv_languages.length > 1 & input.lv_sort != 'top10'", HTML("<label class = 
\"control-label\" style = \"margin-bottom:-30px;\">Aggregation</label>"), 
checkboxInput("lv_combine", "Combine languages", FALSE)),
+              conditionalPanel("input.lv_response === 'clicks' & 
input.lv_languages.length < 2", radioButtons("lv_type", "Type", list("Counts" = 
"count", "Proportions" = "prop"), inline = TRUE)),
+              conditionalPanel("input.lv_type === 'count'", HTML("<label class 
= \"control-label\" style = \"margin-bottom:-30px;\">Scale</label>"), 
checkboxInput("lv_logscale", "Use Log scale", FALSE)),
+              width = 2)
+          ),
+          dygraphOutput("lv_dygraph"),
+          div(id = "lv_legend", class = "large", style = "text-align: center; 
padding: 15px 10px 0 10px;"),
+          includeMarkdown("tab_documentation/languages_visited.md")
+        )
+      )
+    ),
+
+    skin = "black", title = "Portal Traffic Dashboard | Discovery | 
Engineering | Wikimedia Foundation")
+}
diff --git a/www/custom.js b/www/custom.js
index ccce561..d10622a 100644
--- a/www/custom.js
+++ b/www/custom.js
@@ -10,4 +10,9 @@
     // Reveals the KPI dropdown menu at launch:
     $('ul.sidebar-menu li.treeview').first().addClass('active');
 
+    // Update the URL in the browser when a tab is clicked on:
+    $('a[href^="#shiny-tab"]').click(function(){
+      window.location.hash = encodeURI($(this).attr('data-value'));
+    })
+
 });

-- 
To view, visit https://gerrit.wikimedia.org/r/311156
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I32f0565a86500c3a702ad54cd06b87bf6059a2f4
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/discovery/prince
Gerrit-Branch: master
Gerrit-Owner: Bearloga <mpo...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to