Replace old displayKwics demo

Change-Id: Ie4abf629bedd8093555d574976673db6b755b30a
diff --git a/Readme.md b/Readme.md
index 6e5a829..8bf0a8b 100644
--- a/Readme.md
+++ b/Readme.md
@@ -129,7 +129,7 @@
    kco <- new("KorAPConnection", accessToken = token_bundle[["credentials"]][["access_token"]])
    ```
 
-See also the [the OAuth2 runtime demo using the httr package](./demo/OAuthBrowserflowHttr.R) and the [demo using the httr2 package](./demo/OAuthBrowserflowHttr2.R).
+See also the [displayKwics demo](./demo/displayKwics.R) and the [demo using the httr2 package](./demo/OAuthBrowserflowHttr2.R).
 
 How to request access, only if no access token has been provided or persisted, is illustrated in the [gender variants demo](./demo/pluralGenderVariants.R).
 
diff --git a/demo/00Index b/demo/00Index
index dd195be..9ea1d4a 100644
--- a/demo/00Index
+++ b/demo/00Index
@@ -6,7 +6,7 @@
 mosaicplot                      Visualize frequencies of alternative query terms in relation to other variables
 shiny-frequency-curves          Web application that plots frequency curves with highcharts and shiny
 writtenVsSpoken                 Compare frequencies in written vs. spoken corpora
-displayKwics                    Display query results as KWICs via html
+displayKwics                    Display query results including KWICs (also demonstrates OAuth2 browser workflow with httr)
 light-verb-construction-ca      Collocation analysis to identify light verb constructions matching the pattern "in NN setzen", with result rendered as HTML DataTable
 highcharter-example             Visualize frequencies of optionally alternative terms over time with interactive HTML and JavaScript elements using the package highcharter as wrapper for Highcharts
 recursiveCA                     Show result dataframe of recursvie collocation analysis as pretty HTML tableb y Knitr via Markdown.
@@ -15,4 +15,3 @@
 collocation_score_by_country    Plot collocation scores depending on country of publication using ggplot2.
 pluralGenderVariants            Plot frequencies of the plular gender variants of a word in the core corpus of the Council for German Orthography (OKK) over time.
 OAuthBrowserflowHttr2           Runtime OAuth2 browser flow demonstration using the httr2 package (adjective collocates of »Gendern«)
-OAuthBrowserflowHttr            Runtime OAuth2 browser flow demonstration using the httr package (query results for »Vöner« including KWICs)
diff --git a/demo/OAuthBrowserflowHttr.R b/demo/OAuthBrowserflowHttr.R
deleted file mode 100644
index 47fccd1..0000000
--- a/demo/OAuthBrowserflowHttr.R
+++ /dev/null
@@ -1,22 +0,0 @@
-library(RKorAPClient)
-library(httr)
-library(kableExtra)
-library(dplyr)
-
-query = 'V\u00F6ner' # "Portable packages must use only ASCII characters in their demos.   Use \uxxxx escapes for other characters."
-
-korap_app <-oauth_app("test-korap-client", key = "773NHGM76N7P9b6rLfmpM4", secret = NULL)
-korap_endpoint <- oauth_endpoint(NULL,
-                                 "settings/oauth/authorize",
-                                 "api/v1.0/oauth2/token",
-                                 base_url = "https://korap.ids-mannheim.de")
-token_bundle = oauth2.0_token(korap_endpoint, korap_app, scope = "search match_info", cache = FALSE)
-
-new("KorAPConnection", verbose = TRUE, accessToken = token_bundle[["credentials"]][["access_token"]]) %>%
-  corpusQuery(query, fields = c("textSigle", "pubDate", "corpusTitle", "snippet"),
-              metadataOnly = FALSE) %>%
-  fetchAll() %>%
-  slot("collectedMatches") %>%
-  dplyr::arrange(pubDate) %>%
-  kable(escape = FALSE, caption = paste0("Query hits for '", query, "' ordered by date of publication")) %>%
-  kable_styling()
diff --git a/demo/displayKwics.R b/demo/displayKwics.R
index b57aae7..4da6540 100644
--- a/demo/displayKwics.R
+++ b/demo/displayKwics.R
@@ -1,79 +1,24 @@
 library(RKorAPClient)
+library(httr)
+library(kableExtra)
+library(dplyr)
 
-displayKwics <- function(q, htmlFile = file.path(tempfile(fileext = ".html"))) {
-  cat(
-    '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-    <!DOCTYPE html>
-    <html>
-     <header>
-      <style>
-            body {
-              font-family: "Lato", sans-serif;
-              font-size: 10pt;
-            }
-            div.kwic {
-                display: table-row;
-                line-height: 180%;
-            }
-            div.kwic:nth-child(even) {background: #EEE}
-            div.kwic:nth-child(odd) {background: #FFF}
-            .sigle {
-                font-size: 90%;
-                font-family: "Courier New", monospace;
-                display: table-cell;
-                text-align: right;
-                padding-right: 1ex;
-            }
-            .context-left {
-                display: table-cell;
-                text-align: right;
-                overflow: hidden;
-                white-space: nowrap;
-            }
-            .context-right {
-                display: table-cell;
-                text-align: left;
-                white-space: nowrap;
-                overflow: hidden;
-            }
-            .match {
-                display: table-cell;
-                padding-left: 1ex;
-                padding-right: 1ex;
-                text-align: center;
-            }
-      </style>
-    </header>
-    <body>
-      <table>',
-    paste0(
-      "<div class='kwic'><span class='sigle'>",
-      q@collectedMatches$textSigle,
-      "</span> ",
-      as.character(q@collectedMatches$snippet),
-      "</div>"
-    ),
-    '      </table>
-    </body>
-</html>',
-    file = htmlFile,
-    sep = "\n"
-  )
-  viewer <- getOption("viewer")
-  viewer(htmlFile)
-}
+query = 'V\u00F6ner' # "Portable packages must use only ASCII characters in their demos."
 
-kco <- new("KorAPConnection", verbose = TRUE)
-if (is.null(kco@accessToken)) {
-  message(
-    paste0(
-      "In order to receive KWICSs also from corpora with restricted licenses, you need an access token.\n",
-      "To generate an access token, login to KorAP and navigite to KorAP's OAuth settings <",
-      kco@KorAPUrl,
-      "settings/oauth#page-top>"
-    )
-  )
-}
-q <- corpusQuery(kco, "Ameisenplage", metadataOnly = F) %>%
+korap_app <-oauth_app("test-korap-client", key = "773NHGM76N7P9b6rLfmpM4", secret = NULL)
+korap_endpoint <- oauth_endpoint(NULL,
+                                 "settings/oauth/authorize",
+                                 "api/v1.0/oauth2/token",
+                                 base_url = "https://korap.ids-mannheim.de")
+token_bundle = oauth2.0_token(korap_endpoint, korap_app, scope = "search match_info", cache = FALSE)
+
+new("KorAPConnection", verbose = TRUE, accessToken = token_bundle[["credentials"]][["access_token"]]) %>%
+  corpusQuery(query, fields = c("textSigle", "pubDate", "corpusTitle", "snippet"),
+              metadataOnly = FALSE) %>%
   fetchAll() %>%
-  displayKwics()
+  slot("collectedMatches") %>%
+  dplyr::arrange(pubDate) %>%
+  dplyr::rename("kwic" = "snippet") %>%
+  kable(escape = FALSE, caption = paste0("Query hits for '", query, "' ordered by date of publication")) %>%
+  kable_styling() %>%
+  print()