I would like to figure out, which feature of my shiny app is used most...
What is the preferred way on doing this?
At the moment I parse the shiny server access.log
and could find some links like
.../session/69d4f32b3abc77e71097ae4beefbd135/dataobj/lifecycle_table
which indicates when a DT
object called lifecycle_table
is loaded. But I can only see this for these DT
objects.
Are there better ways?
Would love to create this statistics per unique IP. Basically which tabs are clicked. I am not interested in the search strings etc.
Edit: For getting info about the clicked tabs have a look in: ?tabsetPanel
You see that you can specify an id for the panel.
So tabsetPanel(id="tabs",...) will enable you to track the selected tabpanel on the server side with input$tabs.
See an example below: (based on https://shiny.rstudio.com/articles/tabsets.html)
library(shiny)
ui <- shinyUI(pageWithSidebar(
# Application title
headerPanel("Tabsets"),
# Sidebar with controls to select the random distribution type
# and number of observations to generate. Note the use of the br()
# element to introduce extra vertical spacing
sidebarPanel(
radioButtons("dist", "Distribution type:",
list("Normal" = "norm",
"Uniform" = "unif",
"Log-normal" = "lnorm",
"Exponential" = "exp")),
br(),
sliderInput("n",
"Number of observations:",
value = 500,
min = 1,
max = 1000)
),
# Show a tabset that includes a plot, summary, and table view
# of the generated distribution
mainPanel(
tabsetPanel(id = "tabs",
tabPanel("Plot", plotOutput("plot")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Visited Tabs", tableOutput("table"))
)
)
))
# Define server logic for random distribution application
server <- shinyServer(function(input, output, session) {
global <- reactiveValues(visitedTabs = c())
# Reactive expression to generate the requested distribution. This is
# called whenever the inputs change. The renderers defined
# below then all use the value computed from this expression
data <- reactive({
dist <- switch(input$dist,
norm = rnorm,
unif = runif,
lnorm = rlnorm,
exp = rexp,
rnorm)
dist(input$n)
})
observe({
input$tabs
isolate({
userTabInfo <- paste0(" selected: ",input$tabs)
print(userTabInfo)
global$visitedTabs = c(global$visitedTabs, userTabInfo)
})
})
# Generate a plot of the data. Also uses the inputs to build the
# plot label. Note that the dependencies on both the inputs and
# the 'data' reactive expression are both tracked, and all expressions
# are called in the sequence implied by the dependency graph
output$plot <- renderPlot({
dist <- input$dist
n <- input$n
hist(data(),
main=paste('r', dist, '(', n, ')', sep=''))
})
# Generate a summary of the data
output$summary <- renderPrint({
str(session$userData)
# session$user
})
# Generate an HTML table view of the data
output$table <- renderTable({
data.frame(global$visitedTabs)
})
})
shinyApp(ui, server)
Concerning the IP: I know about 4-5 code snippets to get the IP and they all use JSS or XSS-style how you call it :) I agree it should be somehow possible, but since people already asked 3-4 years ago, I am not sure its really a matter of awareness from the shiny team. Hope the tab tracking helps anyway. If you like I can add the JS snippet to get the IP again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With