cjerzak commited on
Commit
089f30d
·
verified ·
1 Parent(s): 40dbcb1

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +99 -0
app.R CHANGED
@@ -36,7 +36,106 @@ ui <- dashboardPage(
36
  "Gender", "Religion", "Language"),
37
  selected = "Overall"
38
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  )
 
40
  ),
41
  dashboardBody(
42
  tags$head(
 
36
  "Gender", "Religion", "Language"),
37
  selected = "Overall"
38
  )
39
+ ),
40
+
41
+ # ---- Here is the minimal "Share" button HTML + JS inlined in Shiny ----
42
+ # We wrap it in tags$div(...) and tags$script(HTML(...)) so it is recognized
43
+ # by Shiny. You can adjust the styling or placement as needed.
44
+ tags$div(
45
+ style = "text-align: left; margin: 1em 0 1em 2em;",
46
+ HTML('
47
+ <button id="share-button"
48
+ style="
49
+ display: inline-flex;
50
+ align-items: center;
51
+ justify-content: center;
52
+ gap: 8px;
53
+ padding: 5px 10px;
54
+ font-size: 16px;
55
+ font-weight: normal;
56
+ color: #000;
57
+ background-color: #fff;
58
+ border: 1px solid #ddd;
59
+ border-radius: 6px;
60
+ cursor: pointer;
61
+ box-shadow: 0 1.5px 0 #000;
62
+ ">
63
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor"
64
+ stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
65
+ <circle cx="18" cy="5" r="3"></circle>
66
+ <circle cx="6" cy="12" r="3"></circle>
67
+ <circle cx="18" cy="19" r="3"></circle>
68
+ <line x1="8.59" y1="13.51" x2="15.42" y2="17.49"></line>
69
+ <line x1="15.41" y1="6.51" x2="8.59" y2="10.49"></line>
70
+ </svg>
71
+ <strong>Share</strong>
72
+ </button>
73
+ '),
74
+ # Insert the JS as well
75
+ tags$script(
76
+ HTML("
77
+ (function() {
78
+ const shareBtn = document.getElementById('share-button');
79
+
80
+ // Reusable helper function to show a small “Copied!” message
81
+ function showCopyNotification() {
82
+ const notification = document.createElement('div');
83
+ notification.innerText = 'Copied to clipboard';
84
+ notification.style.position = 'fixed';
85
+ notification.style.bottom = '20px';
86
+ notification.style.right = '20px';
87
+ notification.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
88
+ notification.style.color = '#fff';
89
+ notification.style.padding = '8px 12px';
90
+ notification.style.borderRadius = '4px';
91
+ notification.style.zIndex = '9999';
92
+ document.body.appendChild(notification);
93
+ setTimeout(() => { notification.remove(); }, 2000);
94
+ }
95
+
96
+ shareBtn.addEventListener('click', function() {
97
+ const currentURL = window.location.href;
98
+ const pageTitle = document.title || 'Check this out!';
99
+
100
+ // If browser supports Web Share API
101
+ if (navigator.share) {
102
+ navigator.share({
103
+ title: pageTitle,
104
+ text: 'Thought you’d like this!',
105
+ url: currentURL
106
+ })
107
+ .catch((error) => {
108
+ console.log('Sharing failed', error);
109
+ });
110
+ } else {
111
+ // Fallback: Copy URL
112
+ if (navigator.clipboard && navigator.clipboard.writeText) {
113
+ navigator.clipboard.writeText(currentURL).then(() => {
114
+ showCopyNotification();
115
+ }, (err) => {
116
+ console.error('Could not copy text: ', err);
117
+ });
118
+ } else {
119
+ // Double fallback for older browsers
120
+ const textArea = document.createElement('textarea');
121
+ textArea.value = currentURL;
122
+ document.body.appendChild(textArea);
123
+ textArea.select();
124
+ try {
125
+ document.execCommand('copy');
126
+ showCopyNotification();
127
+ } catch (err) {
128
+ alert('Please copy this link:\\n' + currentURL);
129
+ }
130
+ document.body.removeChild(textArea);
131
+ }
132
+ }
133
+ });
134
+ })();
135
+ ")
136
+ )
137
  )
138
+ # ---- End: Minimal Share button snippet ----
139
  ),
140
  dashboardBody(
141
  tags$head(