【问题标题】:analysing shiny server log to create statistics on usage分析闪亮的服务器日志以创建有关使用情况的统计信息
【发布时间】:2017-01-18 12:03:28
【问题描述】:

我想弄清楚,我的闪亮应用程序的哪个功能使用得最多... 这样做的首选方法是什么? 目前我解析闪亮的服务器access.log 并可以找到一些链接,如 .../session/69d4f32b3abc77e71097ae4beefbd135/dataobj/lifecycle_table 指示何时加载名为 lifecycle_tableDT 对象。但我只能看到这些 DT 对象。 有没有更好的方法? 希望为每个唯一 IP 创建此统计信息。基本上点击了哪些标签。我对搜索字符串等不感兴趣。

【问题讨论】:

  • 编写自己的日志文件。每次激活您感兴趣的反应式上下文时,您都可以将相关信息写入日志文件并对其进行统计。
  • @nicola 如何在选择选项卡时触发某些内容?

标签: r shiny


【解决方案1】:

编辑:要获取有关单击的选项卡的信息,请查看:?tabsetPanel 您会看到您可以为面板指定一个 id。 因此 tabsetPanel(id="tabs",...) 将使您能够使用 input$tabs 在服务器端跟踪选定的 tabpanel。

参见下面的示例:(基于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)

关于 IP:我知道大约 4-5 个代码 sn-ps 来获取 IP,它们都使用 JSS 或 XSS 风格,你怎么称呼它:) 我同意这应该是可能的,但既然人们已经问过 3 -4 年前,我不确定这是否真的是闪亮团队的意识问题。希望标签跟踪无论如何都有帮助。如果你喜欢我可以添加 JS sn-p 再次获取 IP。

【讨论】:

  • Puh,我对跟踪输入不感兴趣,但这是一个不错的解决方案。无论如何,我不喜欢调用 freegeoip...闪亮的服务器已经知道用户的 IP。难道没有别的办法了吗?你的看起来有点像 XSS :-) 或者实际上是......
  • 嗨@drmariod。哦,我想我回答了另一个问题,这对我来说更有趣;)无论如何,请参阅上面的编辑以仅跟踪没有输入的选项卡。关于 IP:我知道大约 4-5 个代码 sn-ps 来获取 IP,它们都使用 JSS 或 XSS 风格,你怎么称呼它:) 我同意这应该是可能的,但是因为人们已经问了 3-4 年以前,我不确定这是否真的是闪亮团队的意识问题。希望标签跟踪能有所帮助。
猜你喜欢
  • 2017-04-17
  • 2017-07-17
  • 1970-01-01
  • 2010-09-24
  • 2021-11-04
  • 1970-01-01
  • 2021-08-12
  • 2015-01-04
相关资源
最近更新 更多