-
Notifications
You must be signed in to change notification settings - Fork 0
/
TecDoc_Shiny.html
277 lines (251 loc) · 11.2 KB
/
TecDoc_Shiny.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.2.335">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="">
<meta name="dcterms.date" content="2023-04-28">
<title>User Guide</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
</style>
<script src="TecDoc_Shiny_files/libs/clipboard/clipboard.min.js"></script>
<script src="TecDoc_Shiny_files/libs/quarto-html/quarto.js"></script>
<script src="TecDoc_Shiny_files/libs/quarto-html/popper.min.js"></script>
<script src="TecDoc_Shiny_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="TecDoc_Shiny_files/libs/quarto-html/anchor.min.js"></script>
<link href="TecDoc_Shiny_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="TecDoc_Shiny_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="TecDoc_Shiny_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="TecDoc_Shiny_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="TecDoc_Shiny_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
</head>
<body class="fullcontent">
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title">User Guide</h1>
<p class="subtitle lead">for Image Clustering and Analysis in Shiny</p>
</div>
<div class="quarto-title-meta">
<div>
<div class="quarto-title-meta-heading">Author</div>
<div class="quarto-title-meta-contents">
<p><a href="https://github.com/TheArmbreaker" target="_blank"><img src="https://img.shields.io/badge/Github-Markus%20Armbrecht-orange" alt="Github Markus Armbrecht"></a> </p>
</div>
</div>
<div>
<div class="quarto-title-meta-heading">Published</div>
<div class="quarto-title-meta-contents">
<p class="date">April 28, 2023</p>
</div>
</div>
</div>
</header>
<p>This document covers basics features to use the deployed app and also highlights very specific codeing challenges.<br>
Code which is deemed to be not very surprising is commented in the source code of app.R.</p>
<p>The template / theme for the shiny app was provided by the <a href="http://github.com/dataprofessor">Data Professor</a> and Winston Chang on Github and further modified by myself.</p>
<section id="loading-data-and-model" class="level2">
<h2 class="anchored" data-anchor-id="loading-data-and-model">Loading Data and Model</h2>
<p>The data is loaded from the model results, which are stored in CSV-files. Based on the selection the csv-file is loaded.</p>
<p>The options with _predict reflect the results from the recipe-workflow. Those without are the results from Base R code.</p>
<ul>
<li>Flowers</li>
<li>Weapons</li>
<li>Flowers_predict</li>
<li>Weapons_predict</li>
</ul>
<p>To load the model for prediction the selection is used. As the baseR-model is not deployed, the model is loaded based on the substring before “_predict”.</p>
</section>
<section id="loading-images" class="level2">
<h2 class="anchored" data-anchor-id="loading-images">Loading Images</h2>
<p>The images are loaded with an ObserveEvent-function - either based on a cluster-prediction or cluster-selection. Based on the requested cluster four random files are sampled and rendered.</p>
<p>Code for loading and displaying images is separated from each another to prevent images from overlapping and contain the output in a div-container.</p>
<p>The loading function uses local() to render each image in a separate environment and append it to the server-output. The output will then be displayed via a renderUI-function that utilizes the outputImage() function.</p>
<p>This very specific solution is based on this <a href="https://stackoverflow.com/a/69400158/19730678">Stackoverflow</a> post. It was re-designed with lists and other approaches, but turned out to be the only working approach.<br>
Therin the local() function is key to success for the rendering. If this is not used, the [[output]] will be overwritten and the same image is displayed four times. Further details on the local() function can be found in this post on <a href="https://stackoverflow.com/a/10904810/19730678">Stackoverflow</a>.</p>
</section>
<section id="cluster-new-images" class="level2">
<h2 class="anchored" data-anchor-id="cluster-new-images">Cluster New Images</h2>
<p>The page to cluster images enables the upload of new pictures and prediction of a cluster. Only .png and .jpg files can be uploaded.</p>
<p>The prediction will use a reactiveValue for displaying example images of the predicted cluster.</p>
</section>
<section id="show-clusters" class="level2">
<h2 class="anchored" data-anchor-id="show-clusters">Show Clusters</h2>
<p>The show clusters page enables the investigation of cluster content.<br>
The displayed images depend on the selected cluster. This also shows Base R results to explore differences.</p>
<p>Furthermore the cluster can be labeled with a name. This string is a dummy and might be connected to an sql database for actually storing the input.</p>
</section>
<section id="dataset" class="level2">
<h2 class="anchored" data-anchor-id="dataset">Dataset</h2>
<ul>
<li>Weapons in Images on <a href="https://www.kaggle.com/datasets/jubaerad/weapons-in-images-segmented-videos">kaggle.com</a></li>
<li>Flower Color Images on <a href="https://www.kaggle.com/datasets/olgabelitskaya/flower-color-images">kaggle.com</a></li>
</ul>
</section>
<section id="models" class="level2">
<h2 class="anchored" data-anchor-id="models">Models</h2>
<p>Download the RDS files from <a href="https://drive.google.com/drive/folders/1LQ2Ixx4rwxcAW8TQPocOXQnUKcDCvBSE?usp=share_link">GoogleDrive</a></p>
</section>
</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const clipboard = new window.ClipboardJS('.code-copy-button', {
target: function(trigger) {
return trigger.previousElementSibling;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
tooltip.hide();
button.removeAttribute("data-bs-title");
button.removeAttribute("data-bs-toggle");
button.removeAttribute("data-bs-placement");
}
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
const findCites = (el) => {
const parentEl = el.parentElement;
if (parentEl) {
const cites = parentEl.dataset.cites;
if (cites) {
return {
el,
cites: cites.split(' ')
};
} else {
return findCites(el.parentElement)
}
} else {
return undefined;
}
};
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const citeInfo = findCites(ref);
if (citeInfo) {
tippyHover(citeInfo.el, function() {
var popup = window.document.createElement('div');
citeInfo.cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
}
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
var filterRegex = new RegExp('/' + window.location.host + '/');
var isInternal = (href) => {
return filterRegex.test(href) || localhostRegex.test(href);
}
// Inspect non-navigation links and adorn them if external
var links = window.document.querySelectorAll('a:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item)');
for (var i=0; i<links.length; i++) {
const link = links[i];
if (!isInternal(link.href)) {
// target, if specified
link.setAttribute("target", "_blank");
}
}
});
</script>
</div> <!-- /content -->
</body></html>