cjerzak commited on
Commit
4a286a3
·
verified ·
1 Parent(s): 5ed704e

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +81 -81
app.R CHANGED
@@ -117,90 +117,89 @@ ui <- fluidPage(
117
  tags$div(
118
  style = "text-align: left; margin: 0.5em 0 0.5em 0em;",
119
  HTML('
120
- <button id="share-button"
121
- style="
122
- display: inline-flex;
123
- align-items: center;
124
- justify-content: center;
125
- gap: 8px;
126
- padding: 5px 10px;
127
- font-size: 16px;
128
- font-weight: normal;
129
- color: #000;
130
- background-color: #fff;
131
- border: 1px solid #ddd;
132
- border-radius: 6px;
133
- cursor: pointer;
134
- box-shadow: 0 1.5px 0 #000;
135
- ">
136
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor"
137
- stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
138
- <circle cx="18" cy="5" r="3"></circle>
139
- <circle cx="6" cy="12" r="3"></circle>
140
- <circle cx="18" cy="19" r="3"></circle>
141
- <line x1="8.59" y1="13.51" x2="15.42" y2="17.49"></line>
142
- <line x1="15.41" y1="6.51" x2="8.59" y2="10.49"></line>
143
- </svg>
144
- <strong>Share</strong>
145
- </button>
146
  '),
147
  tags$script(
148
  HTML("
149
- (function() {
150
- const shareBtn = document.getElementById('share-button');
151
- // Reusable helper function to show a small “Copied!” message
152
- function showCopyNotification() {
153
- const notification = document.createElement('div');
154
- notification.innerText = 'Copied to clipboard';
155
- notification.style.position = 'fixed';
156
- notification.style.bottom = '20px';
157
- notification.style.right = '20px';
158
- notification.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
159
- notification.style.color = '#fff';
160
- notification.style.padding = '8px 12px';
161
- notification.style.borderRadius = '4px';
162
- notification.style.zIndex = '9999';
163
- document.body.appendChild(notification);
164
- setTimeout(() => { notification.remove(); }, 2000);
165
- }
166
- shareBtn.addEventListener('click', function() {
167
- const currentURL = window.location.href;
168
- const pageTitle = document.title || 'Check this out!';
169
- // If browser supports Web Share API
170
- if (navigator.share) {
171
- navigator.share({
172
- title: pageTitle,
173
- text: '',
174
- url: currentURL
175
- })
176
- .catch((error) => {
177
- console.log('Sharing failed', error);
178
- });
179
- } else {
180
- // Fallback: Copy URL
181
- if (navigator.clipboard && navigator.clipboard.writeText) {
182
- navigator.clipboard.writeText(currentURL).then(() => {
183
- showCopyNotification();
184
- }, (err) => {
185
- console.error('Could not copy text: ', err);
186
- });
187
- } else {
188
- // Double fallback for older browsers
189
- const textArea = document.createElement('textarea');
190
- textArea.value = currentURL;
191
- document.body.appendChild(textArea);
192
- textArea.select();
193
- try {
194
- document.execCommand('copy');
195
- showCopyNotification();
196
- } catch (err) {
197
- alert('Please copy this link:\\n' + currentURL);
198
- }
199
- document.body.removeChild(textArea);
200
- }
201
- }
202
- });
203
- })();
204
  ")
205
  )
206
  ),
@@ -377,3 +376,4 @@ server <- function(input, output, session) {
377
  # Run the app
378
  shinyApp(ui, server)
379
 
 
 
117
  tags$div(
118
  style = "text-align: left; margin: 0.5em 0 0.5em 0em;",
119
  HTML('
120
+ <button id="share-button"
121
+ style="
122
+ display: inline-flex;
123
+ align-items: center;
124
+ justify-content: center;
125
+ gap: 8px;
126
+ padding: 5px 10px;
127
+ font-size: 16px;
128
+ font-weight: normal;
129
+ color: #000;
130
+ background-color: #fff;
131
+ border: 1px solid #ddd;
132
+ border-radius: 6px;
133
+ cursor: pointer;
134
+ box-shadow: 0 1.5px 0 #000;
135
+ ">
136
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor"
137
+ stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
138
+ <circle cx="18" cy="5" r="3"></circle>
139
+ <circle cx="6" cy="12" r="3"></circle>
140
+ <circle cx="18" cy="19" r="3"></circle>
141
+ <line x1="8.59" y1="13.51" x2="15.42" y2="17.49"></line>
142
+ <line x1="15.41" y1="6.51" x2="8.59" y2="10.49"></line>
143
+ </svg>
144
+ <strong>Share</strong>
145
+ </button>
146
  '),
147
  tags$script(
148
  HTML("
149
+ (function () {
150
+ const shareBtn = document.getElementById('share-button');
151
+
152
+ function showCopyNotification(targetBtn) {
153
+ const notification = document.createElement('div');
154
+ notification.innerText = 'Copied to clipboard';
155
+ notification.style.position = 'absolute';
156
+ notification.style.pointerEvents = 'none';
157
+ notification.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
158
+ notification.style.color = '#fff';
159
+ notification.style.padding = '6px 10px';
160
+ notification.style.borderRadius = '4px';
161
+ notification.style.fontSize = '14px';
162
+ notification.style.whiteSpace = 'nowrap';
163
+ notification.style.zIndex = '10000';
164
+
165
+ const rect = targetBtn.getBoundingClientRect();
166
+ const top = rect.top + window.scrollY - 40; // 40 px above the button
167
+ const left = rect.left + window.scrollX + rect.width / 2;
168
+
169
+ notification.style.top = top + 'px';
170
+ notification.style.left = left + 'px';
171
+ notification.style.transform = 'translateX(-50%)';
172
+
173
+ document.body.appendChild(notification);
174
+ setTimeout(() => notification.remove(), 2000);
175
+ }
176
+
177
+ shareBtn.addEventListener('click', function () {
178
+ const currentURL = window.location.href;
179
+ const pageTitle = document.title || 'Check this out!';
180
+
181
+ if (navigator.share) {
182
+ navigator.share({ title: pageTitle, url: currentURL })
183
+ .catch(error => console.log('Sharing failed', error));
184
+ } else if (navigator.clipboard && navigator.clipboard.writeText) {
185
+ navigator.clipboard.writeText(currentURL)
186
+ .then(() => showCopyNotification(shareBtn))
187
+ .catch(err => console.error('Could not copy text: ', err));
188
+ } else {
189
+ const textArea = document.createElement('textarea');
190
+ textArea.value = currentURL;
191
+ document.body.appendChild(textArea);
192
+ textArea.select();
193
+ try {
194
+ document.execCommand('copy');
195
+ showCopyNotification(shareBtn);
196
+ } catch (err) {
197
+ alert('Please copy this link:\n' + currentURL);
198
+ }
199
+ document.body.removeChild(textArea);
200
+ }
201
+ });
202
+ })();
 
203
  ")
204
  )
205
  ),
 
376
  # Run the app
377
  shinyApp(ui, server)
378
 
379
+