@@ -60,8 +60,9 @@ full_url <- function(session) {
60
60
session $ clientData $ url_protocol ,
61
61
" //" ,
62
62
session $ clientData $ url_hostname ,
63
- if (nzchar(session $ clientData $ url_port ))
64
- paste0(" :" , session $ clientData $ url_port ),
63
+ if (nzchar(session $ clientData $ url_port )) {
64
+ paste0(" :" , session $ clientData $ url_port )
65
+ },
65
66
session $ clientData $ url_pathname
66
67
)
67
68
}
@@ -746,10 +747,41 @@ server <- function(input, output, session) {
746
747
paste0(" Updated " , format(usage_last_updated(), fmt ))
747
748
})
748
749
750
+ # JavaScript for persisting search terms across table rerenders
751
+ table_js <- "
752
+ function(el, x) {
753
+ const tableId = el.id;
754
+ const storageKey = 'search_' + tableId;
755
+
756
+ // Clear search value when the page is refreshed
757
+ window.addEventListener('beforeunload', function() {
758
+ sessionStorage.removeItem(storageKey);
759
+ });
760
+
761
+ const searchInput = el.querySelector('input.rt-search');
762
+ if (!searchInput) return;
763
+
764
+ // Restore previous search if available
765
+ const savedSearch = sessionStorage.getItem(storageKey);
766
+
767
+ if (savedSearch) {
768
+ searchInput.value = savedSearch;
769
+ if (window.Reactable && typeof window.Reactable.setSearch === 'function') {
770
+ window.Reactable.setSearch(tableId, savedSearch);
771
+ }
772
+ }
773
+
774
+ // Save search terms as they're entered
775
+ searchInput.addEventListener('input', function() {
776
+ sessionStorage.setItem(storageKey, this.value);
777
+ });
778
+ }
779
+ "
780
+
749
781
output $ content_usage_table <- renderReactable({
750
782
data <- multi_content_table_data()
751
783
752
- reactable(
784
+ table <- reactable(
753
785
data ,
754
786
defaultSortOrder = " desc" ,
755
787
onClick = JS(
@@ -792,7 +824,9 @@ server <- function(input, output, session) {
792
824
width = 32 ,
793
825
sortable = FALSE ,
794
826
cell = function (url ) {
795
- if (is.na(url ) || url == " " ) return (" " )
827
+ if (is.na(url ) || url == " " ) {
828
+ return (" " )
829
+ }
796
830
HTML(as.character(tags $ div(
797
831
onclick = " event.stopPropagation()" ,
798
832
tags $ a(
@@ -864,6 +898,9 @@ server <- function(input, output, session) {
864
898
)
865
899
)
866
900
)
901
+
902
+ # Apply any onRender JS for capturing search value
903
+ htmlwidgets :: onRender(table , table_js )
867
904
})
868
905
869
906
output $ export_raw_visits <- downloadHandler(
@@ -964,7 +1001,9 @@ server <- function(input, output, session) {
964
1001
width = 32 ,
965
1002
sortable = FALSE ,
966
1003
cell = function (url ) {
967
- if (is.na(url ) || url == " " ) return (" " )
1004
+ if (is.na(url ) || url == " " ) {
1005
+ return (" " )
1006
+ }
968
1007
subject <- glue :: glue(
969
1008
" \" {selected_content_info()$title}\" on Posit Connect"
970
1009
)
@@ -1020,8 +1059,11 @@ server <- function(input, output, session) {
1020
1059
users <- aggregated_visits_data() | >
1021
1060
filter(user_guid %in% input $ selected_users ) | >
1022
1061
pull(display_name )
1023
- user_string <- if (length(users ) == 1 ) users else
1062
+ user_string <- if (length(users ) == 1 ) {
1063
+ users
1064
+ } else {
1024
1065
" multiple selected users"
1066
+ }
1025
1067
tagList(
1026
1068
HTML(glue :: glue(
1027
1069
" {nrow(hits)} visits from <b>{user_string}</b> between " ,
@@ -1121,8 +1163,11 @@ server <- function(input, output, session) {
1121
1163
type = " button" ,
1122
1164
class = " btn btn-sm btn-outline-secondary" ,
1123
1165
disabled = disabled ,
1124
- onclick = if (is.null(disabled ))
1125
- sprintf(" window.location.href='%s'" , mailto ) else NULL ,
1166
+ onclick = if (is.null(disabled )) {
1167
+ sprintf(" window.location.href='%s'" , mailto )
1168
+ } else {
1169
+ NULL
1170
+ },
1126
1171
tagList(icon(" envelope" ), " Email Selected Visitors" )
1127
1172
)
1128
1173
})
0 commit comments