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: I457fb18d6f90d5eb32067a87bbe47002384b80cb
---
A global.R
M server.R
M twilightsparql.Rproj
M ui.R
M www/custom.js
5 files changed, 47 insertions(+), 55 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 753164c..fca3f17 100644
--- a/server.R
+++ b/server.R
@@ -2,18 +2,13 @@
 
 existing_date <- Sys.Date() - 1
 
-shinyServer(function(input, output) {
-  
+shinyServer(function(input, output, session) {
+
   if(Sys.Date() != existing_date){
     read_wdqs()
     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$wdqs_usage_plot <- renderDygraph(
     wdqs_usage %>%
       spider_subset(val = input$include_automata) %>%
@@ -23,14 +18,13 @@
       polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_usage), rename = 
FALSE) %>%
       # ...and then exp10-transformed back to the original scale:
       conditional_transform(input$usage_logscale && 
polloi::smooth_switch(input$smoothing_global, input$smoothing_usage) != "day", 
exp10) %>%
-      polloi::subset_by_date_range(time_frame_range(input$usage_timeframe, 
input$usage_timeframe_daterange)) %>%
       polloi::make_dygraph(xlab = "Date", ylab = "Events", title = "Daily WDQS 
Homepage usage", group = "usage") %>%
       # ...because we're using dygraphs' native log-scaling:
       dyAxis("y", logscale = input$usage_logscale) %>%
       dyLegend(labelsDiv = "usage_legend") %>%
       dyEvent(as.Date("2015-09-07"), "A (Announcement)", labelLoc = "bottom")
   )
-  
+
   output$sparql_usage_plot <- renderDygraph(
     sparql_usage %>%
       spider_subset(val = input$include_automata) %>%
@@ -38,7 +32,6 @@
       conditional_transform(input$usage_logscale && 
polloi::smooth_switch(input$smoothing_global, input$smoothing_usage) != "day", 
log10) %>%
       polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_usage), rename = 
FALSE) %>%
       conditional_transform(input$usage_logscale && 
polloi::smooth_switch(input$smoothing_global, input$smoothing_usage) != "day", 
exp10) %>%
-      polloi::subset_by_date_range(time_frame_range(input$usage_timeframe, 
input$usage_timeframe_daterange)) %>%
       polloi::make_dygraph(xlab = "Date", ylab = "Events", title = "Daily 
SPARQL usage", group = "usage") %>%
       dyLegend(labelsDiv = "usage_legend") %>%
       dyAxis("y", logscale = input$usage_logscale) %>%
@@ -46,7 +39,7 @@
       dyEvent(as.Date("2015-09-07"), "A (Announcement)", labelLoc = "bottom") 
%>%
       dyEvent(as.Date("2015-11-05"), "B (Labs bot)", labelLoc = "bottom")
   )
-  
+
   # Check datasets for missing data and notify user which datasets are missing 
data (if any)
   output$message_menu <- renderMenu({
     notifications <- list(
@@ -55,5 +48,5 @@
     notifications <- notifications[!sapply(notifications, is.null)]
     return(dropdownMenu(type = "notifications", .list = notifications))
   })
-  
+
 })
diff --git a/twilightsparql.Rproj b/twilightsparql.Rproj
index 0a8dc07..d64e28b 100644
--- a/twilightsparql.Rproj
+++ b/twilightsparql.Rproj
@@ -13,3 +13,4 @@
 LaTeX: pdfLaTeX
 
 AutoAppendNewline: Yes
+StripTrailingWhitespace: Yes
diff --git a/ui.R b/ui.R
index c3afb75..537cd97 100644
--- a/ui.R
+++ b/ui.R
@@ -1,49 +1,41 @@
-source("utils.R")
 library(shiny)
 library(shinydashboard)
 library(dygraphs)
 
-# Header elements for the visualization
-header <- dashboardHeader(title = "Wikidata Query Service", 
dropdownMenuOutput("message_menu"), disable = FALSE)
+function(request) {
+  dashboardPage(
 
-# Sidebar elements for the search visualizations
-sidebar <- dashboardSidebar(
-  tags$head(
-    tags$link(rel = "stylesheet", type = "text/css", href = "custom.css"),
-    tags$script(src = "custom.js")
-  ),
-  sidebarMenu(
-    menuItem(text = "WDQS Usage", tabName = "wdqs_usage"),
-    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 = "Wikidata Query Service", 
dropdownMenuOutput("message_menu"), disable = FALSE),
 
-#Body elements for the search visualizations.
-body <- dashboardBody(
-  tabItems(
-    tabItem(tabName = "wdqs_usage",
-            fluidRow(
-              column(polloi::smooth_select("smoothing_usage"), width = 3),
-              column(polloi::timeframe_select("usage_timeframe"), width = 3),
-              column(polloi::timeframe_daterange("usage_timeframe"), width = 
3),
-              column(checkboxInput("usage_logscale", "Use Log scale", TRUE), 
width = 3)),
-            spider_checkbox("include_automata"),
-            dygraphOutput("wdqs_usage_plot", height = "200px"),
-            dygraphOutput("sparql_usage_plot", height = "200px"),
-            fluidRow(div(id = "usage_legend"), style = "padding-top: 10px; 
height: 20px; text-align: center;"),
-            includeMarkdown("./tab_documentation/wdqs_basic.md"))
-  )
-)
+    dashboardSidebar(
+      tags$head(
+        tags$link(rel = "stylesheet", type = "text/css", href = "custom.css"),
+        tags$script(src = "custom.js")
+      ),
+      sidebarMenu(id = "tabs",
+                  menuItem(text = "WDQS Usage", tabName = "wdqs_usage"),
+                  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;")
+    ),
 
-dashboardPage(header, sidebar, body, skin = "purple",
-              title = "WDQS Usage Dashboard | Discovery | Engineering | 
Wikimedia Foundation")
+    dashboardBody(
+      tabItems(
+        tabItem(tabName = "wdqs_usage",
+                fluidRow(
+                  column(polloi::smooth_select("smoothing_usage"), width = 4),
+                  column(checkboxInput("usage_logscale", "Use Log scale", 
TRUE), width = 4),
+                  column(spider_checkbox("include_automata"), width = 4)),
+                dygraphOutput("wdqs_usage_plot", height = "200px"),
+                dygraphOutput("sparql_usage_plot", height = "200px"),
+                fluidRow(div(id = "usage_legend"), style = "padding-top: 10px; 
height: 20px; text-align: center;"),
+                includeMarkdown("./tab_documentation/wdqs_basic.md"))
+      )
+    ),
+
+    skin = "purple", title = "WDQS Usage Dashboard | Discovery | Engineering | 
Wikimedia Foundation")
+}
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/311157
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I457fb18d6f90d5eb32067a87bbe47002384b80cb
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/discovery/twilightsparql
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