Spaces:
Running
Running
Update app.R
Browse files
app.R
CHANGED
|
@@ -83,7 +83,102 @@
|
|
| 83 |
"Spectral (Brewer)" = "Spectral"),
|
| 84 |
selected = "plasma"),
|
| 85 |
sliderInput("opacity", "Map Opacity:", min = 0.2, max = 1, value = 0.8, step = 0.1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
)
|
|
|
|
|
|
|
| 87 |
),
|
| 88 |
|
| 89 |
# -- Body
|
|
|
|
| 83 |
"Spectral (Brewer)" = "Spectral"),
|
| 84 |
selected = "plasma"),
|
| 85 |
sliderInput("opacity", "Map Opacity:", min = 0.2, max = 1, value = 0.8, step = 0.1)
|
| 86 |
+
),
|
| 87 |
+
# ---- Here is the minimal "Share" button HTML + JS inlined in Shiny ----
|
| 88 |
+
# We wrap it in tags$div(...) and tags$script(HTML(...)) so it is recognized
|
| 89 |
+
# by Shiny. You can adjust the styling or placement as needed.
|
| 90 |
+
tags$div(
|
| 91 |
+
style = "text-align: left; margin: 1em 0 1em 2em;",
|
| 92 |
+
HTML('
|
| 93 |
+
<button id="share-button"
|
| 94 |
+
style="
|
| 95 |
+
display: inline-flex;
|
| 96 |
+
align-items: center;
|
| 97 |
+
justify-content: center;
|
| 98 |
+
gap: 8px;
|
| 99 |
+
padding: 5px 10px;
|
| 100 |
+
font-size: 16px;
|
| 101 |
+
font-weight: normal;
|
| 102 |
+
color: #000;
|
| 103 |
+
background-color: #fff;
|
| 104 |
+
border: 1px solid #ddd;
|
| 105 |
+
border-radius: 6px;
|
| 106 |
+
cursor: pointer;
|
| 107 |
+
box-shadow: 0 1.5px 0 #000;
|
| 108 |
+
">
|
| 109 |
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
| 110 |
+
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
| 111 |
+
<circle cx="18" cy="5" r="3"></circle>
|
| 112 |
+
<circle cx="6" cy="12" r="3"></circle>
|
| 113 |
+
<circle cx="18" cy="19" r="3"></circle>
|
| 114 |
+
<line x1="8.59" y1="13.51" x2="15.42" y2="17.49"></line>
|
| 115 |
+
<line x1="15.41" y1="6.51" x2="8.59" y2="10.49"></line>
|
| 116 |
+
</svg>
|
| 117 |
+
<strong>Share</strong>
|
| 118 |
+
</button>
|
| 119 |
+
'),
|
| 120 |
+
# Insert the JS as well
|
| 121 |
+
tags$script(
|
| 122 |
+
HTML("
|
| 123 |
+
(function() {
|
| 124 |
+
const shareBtn = document.getElementById('share-button');
|
| 125 |
+
// Reusable helper function to show a small “Copied!” message
|
| 126 |
+
function showCopyNotification() {
|
| 127 |
+
const notification = document.createElement('div');
|
| 128 |
+
notification.innerText = 'Copied to clipboard';
|
| 129 |
+
notification.style.position = 'fixed';
|
| 130 |
+
notification.style.bottom = '20px';
|
| 131 |
+
notification.style.right = '20px';
|
| 132 |
+
notification.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
|
| 133 |
+
notification.style.color = '#fff';
|
| 134 |
+
notification.style.padding = '8px 12px';
|
| 135 |
+
notification.style.borderRadius = '4px';
|
| 136 |
+
notification.style.zIndex = '9999';
|
| 137 |
+
document.body.appendChild(notification);
|
| 138 |
+
setTimeout(() => { notification.remove(); }, 2000);
|
| 139 |
+
}
|
| 140 |
+
shareBtn.addEventListener('click', function() {
|
| 141 |
+
const currentURL = window.location.href;
|
| 142 |
+
const pageTitle = document.title || 'Check this out!';
|
| 143 |
+
// If browser supports Web Share API
|
| 144 |
+
if (navigator.share) {
|
| 145 |
+
navigator.share({
|
| 146 |
+
title: pageTitle,
|
| 147 |
+
text: 'Thought you’d like this!',
|
| 148 |
+
url: currentURL
|
| 149 |
+
})
|
| 150 |
+
.catch((error) => {
|
| 151 |
+
console.log('Sharing failed', error);
|
| 152 |
+
});
|
| 153 |
+
} else {
|
| 154 |
+
// Fallback: Copy URL
|
| 155 |
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
| 156 |
+
navigator.clipboard.writeText(currentURL).then(() => {
|
| 157 |
+
showCopyNotification();
|
| 158 |
+
}, (err) => {
|
| 159 |
+
console.error('Could not copy text: ', err);
|
| 160 |
+
});
|
| 161 |
+
} else {
|
| 162 |
+
// Double fallback for older browsers
|
| 163 |
+
const textArea = document.createElement('textarea');
|
| 164 |
+
textArea.value = currentURL;
|
| 165 |
+
document.body.appendChild(textArea);
|
| 166 |
+
textArea.select();
|
| 167 |
+
try {
|
| 168 |
+
document.execCommand('copy');
|
| 169 |
+
showCopyNotification();
|
| 170 |
+
} catch (err) {
|
| 171 |
+
alert('Please copy this link:\\n' + currentURL);
|
| 172 |
+
}
|
| 173 |
+
document.body.removeChild(textArea);
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
});
|
| 177 |
+
})();
|
| 178 |
+
")
|
| 179 |
)
|
| 180 |
+
)
|
| 181 |
+
# ---- End: Minimal Share button snippet ----
|
| 182 |
),
|
| 183 |
|
| 184 |
# -- Body
|