cjerzak commited on
Commit
abba9a0
·
verified ·
1 Parent(s): 0c3cd56

Update app.R

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