Chelsyx has submitted this change and it was merged.

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: Iab2b2a84707e4438567d651b9df327ce221292ee
---
A global.R
M server.R
M ui.R
M wonderbolt.Rproj
M www/custom.js
5 files changed, 56 insertions(+), 66 deletions(-)

Approvals:
  Chelsyx: Verified; Looks good to me, approved



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/server.R b/server.R
index 3b2fa03..1888f89 100644
--- a/server.R
+++ b/server.R
@@ -1,23 +1,21 @@
+library(shiny)
+library(shinydashboard)
+library(dygraphs)
+
 source("utils.R")
 
 existing_date <- Sys.Date() - 1
 
-shinyServer(function(input, output){
+function(input, output, session) {
   
   if (Sys.Date() != existing_date) {
     read_traffic()
     existing_date <<- Sys.Date()
   }
   
-  # Wrap time_frame_range to provide global settings
-  time_frame_range <- function(input_local_timeframe, input_local_daterange) {
-    return(polloi::time_frame_range(input_local_timeframe, 
input_local_daterange, input$timeframe_global, input$daterange_global))
-  }
-  
   output$traffic_summary_dygraph <- renderDygraph({
     summary_traffic_data[[input$platform_traffic_summary]] %>%
       polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_traffic_summary)) 
%>%
-      
polloi::subset_by_date_range(time_frame_range(input$traffic_summary_timeframe, 
input$traffic_summary_timeframe_daterange)) %>%
       polloi::make_dygraph(xlab = "Date", ylab = "Pageviews",
                            title = "Sources of page views (e.g. search engines 
and internal referers)") %>%
       dyLegend(labelsDiv = "traffic_summary_legend", show = "always", 
showZeroValues = FALSE) %>%
@@ -29,7 +27,6 @@
   output$traffic_bysearch_dygraph <- renderDygraph({
     bysearch_traffic_data[[input$platform_traffic_bysearch]] %>%
       polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, 
input$smoothing_traffic_bysearch)) %>%
-      
polloi::subset_by_date_range(time_frame_range(input$traffic_bysearch_timeframe, 
input$traffic_bysearch_timeframe_daterange)) %>%
       polloi::make_dygraph(xlab = "Date", ylab = "Pageviews",
                            title = "Pageviews from external search engines, 
broken down by engine") %>%
       dyLegend(labelsDiv = "traffic_bysearch_legend", show = "always", 
showZeroValues = FALSE) %>%
@@ -47,4 +44,4 @@
     return(dropdownMenu(type = "notifications", .list = notifications))
   })
   
-})
+}
diff --git a/ui.R b/ui.R
index 8b7bd7f..358e8a9 100644
--- a/ui.R
+++ b/ui.R
@@ -2,64 +2,50 @@
 library(shinydashboard)
 library(dygraphs)
 
-#Header elements for the visualisation
-header <- dashboardHeader(title = "External Search Traffic", 
dropdownMenuOutput("message_menu"), disable = FALSE)
+function(request) {
+  dashboardPage(
 
-sidebar <- dashboardSidebar(
-  tags$head(
-    tags$link(rel = "stylesheet", type = "text/css", href = "stylesheet.css"),
-    tags$script(src = "custom.js")
-  ),
-  sidebarMenu(
-    menuItem(text = "Traffic",
-             menuSubItem(text = "Summary", tabName = "traffic_summary"),
-             menuSubItem(text = "Pageviews by search engine", tabName = 
"traffic_by_engine")),
-    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")),
-             selectInput(inputId = "timeframe_global", label = "Time Frame", 
selectize = TRUE, selected = "",
-                         choices = c("All available data" = "all", "Last 7 
days" = "week", "Last 30 days" = "month",
-                                     "Last 90 days" = "quarter", "Custom" = 
"custom")),
-             conditionalPanel("input.timeframe_global == 'custom'",
-                              dateRangeInput("daterange_global", label = 
"Custom Date Range",
-                                             start = Sys.Date()-11, end = 
Sys.Date()-1, min = "2015-04-14")),
-             icon = icon("cog", 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: white;")
-)
+    dashboardHeader(title = "External Search Traffic", 
dropdownMenuOutput("message_menu"), disable = FALSE),
 
-# Custom function to allow for the selection betwene
-platform_select <- function(name){
-  return(selectizeInput(inputId = name, label = "Platform",
-                        choices = c("All","Desktop","Mobile Web")))
-}
-
-body <- dashboardBody(
-  tabItems(
-    tabItem(tabName = "traffic_summary",
-            fluidRow(
-              column(platform_select("platform_traffic_summary"), width = 3),
-              column(polloi::smooth_select("smoothing_traffic_summary"), width 
= 3),
-              column(polloi::timeframe_select("traffic_summary_timeframe"), 
width = 3),
-              column(polloi::timeframe_daterange("traffic_summary_timeframe"), 
width = 3)),
-            dygraphOutput("traffic_summary_dygraph"),
-            div(id = "traffic_summary_legend", style = "text-align: right;"),
-            includeMarkdown("./tab_documentation/traffic_summary.md")
+    dashboardSidebar(
+      tags$head(
+        tags$link(rel = "stylesheet", type = "text/css", href = 
"stylesheet.css"),
+        tags$script(src = "custom.js")
+      ),
+      sidebarMenu(id = "tabs",
+                  menuItem(text = "Traffic",
+                           menuSubItem(text = "Summary", tabName = 
"traffic_summary"),
+                           menuSubItem(text = "Pageviews by search engine", 
tabName = "traffic_by_engine")),
+                  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")),
+                           icon = icon("cog", 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: white;"),
+      div(bookmarkButton(), style = "text-align: center;")
     ),
-    tabItem(tabName = "traffic_by_engine",
-            fluidRow(
-              column(platform_select("platform_traffic_bysearch"),
-                     checkboxInput("platform_traffic_bysearch_log", label = 
"Use Log scale", value = FALSE),
-                     width = 3),
-              column(polloi::smooth_select("smoothing_traffic_bysearch"), 
width = 3),
-              column(polloi::timeframe_select("traffic_bysearch_timeframe"), 
width = 3),
-              
column(polloi::timeframe_daterange("traffic_bysearch_timeframe"), width = 3)),
-            dygraphOutput("traffic_bysearch_dygraph"),
-            div(id = "traffic_bysearch_legend", style = "text-align: right;"),
-            includeMarkdown("./tab_documentation/traffic_byengine.md")
-    )
-  )
-)
 
-dashboardPage(header, sidebar, body, skin = "black",
-              title = "External Search Dashboard | Discovery | Engineering | 
Wikimedia Foundation")
+    dashboardBody(
+      tabItems(
+        tabItem(tabName = "traffic_summary",
+                fluidRow(
+                  column(selectizeInput(inputId = "platform_traffic_summary", 
label = "Platform", choices = c("All", "Desktop", "Mobile Web")), width = 2),
+                  column(polloi::smooth_select("smoothing_traffic_summary"), 
width = 3),
+                  column(div(id = "traffic_summary_legend", style = 
"text-align: right;"), width = 7)),
+                dygraphOutput("traffic_summary_dygraph"),
+                includeMarkdown("./tab_documentation/traffic_summary.md")
+        ),
+        tabItem(tabName = "traffic_by_engine",
+                fluidRow(
+                  column(selectizeInput(inputId = "platform_traffic_bysearch", 
label = "Platform", choices = c("All", "Desktop", "Mobile Web")), width = 2),
+                  column(HTML("<label class = \"control-label\" style = 
\"margin-bottom:-30px;\">Scale</label>"), 
checkboxInput("platform_traffic_bysearch_log", label = "Use Log scale", value = 
FALSE), width = 2),
+                  column(polloi::smooth_select("smoothing_traffic_bysearch"), 
width = 3),
+                  column(div(id = "traffic_bysearch_legend", style = 
"text-align: right;"), width = 5)),
+                dygraphOutput("traffic_bysearch_dygraph"),
+                includeMarkdown("./tab_documentation/traffic_byengine.md")
+        )
+      )
+    ),
+
+    skin = "black", title = "External Search Dashboard | Discovery | 
Engineering | Wikimedia Foundation")
+}
diff --git a/wonderbolt.Rproj b/wonderbolt.Rproj
index a213108..e83436a 100644
--- a/wonderbolt.Rproj
+++ b/wonderbolt.Rproj
@@ -13,3 +13,4 @@
 LaTeX: pdfLaTeX
 
 AutoAppendNewline: Yes
+StripTrailingWhitespace: Yes
diff --git a/www/custom.js b/www/custom.js
index f02b367..d229d68 100644
--- a/www/custom.js
+++ b/www/custom.js
@@ -9,5 +9,10 @@
     
     // 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/311159
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iab2b2a84707e4438567d651b9df327ce221292ee
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/discovery/wonderbolt
Gerrit-Branch: master
Gerrit-Owner: Bearloga <mpo...@wikimedia.org>
Gerrit-Reviewer: Chelsyx <c...@wikimedia.org>

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

Reply via email to