Tho*_*mas 6 javascript jquery google-analytics r shiny
我读过我通过伟大的教程在这里。但是,我对jQuery的了解为零。我在ShinyApp中使用了几个tabPanels来显示我的数据。本教程说明了如何跟踪链接单击事件(效果很好,我在本教程中介绍了一个.js)。有没有一种方法可以跟踪用户是否单击了特定的tabPanel(例如Panel1和Panel2)?我尝试使用指向外部资源的链接进行相同的操作,但这不起作用。
tabsetPanel(
tabPanel("Panel1", showOutput("PlotPanel1", 'dimple')),
tabPanel("Panel2", showOutput("PlotPanel2", 'dimple')))
Run Code Online (Sandbox Code Playgroud)
编辑:
我想我必须在我的analytics.js文件中包含一些代码。因此,我尝试了几件事,但是坦率地说,由于不了解jQuery,这是错误的。有人可以帮忙吗?
$( ".selector" ).tabs({
on('option', 'click', function(l) {
ga('send', 'event', 'tabPanel', 'tabPanel', $(l.currentTarget).val());
}
});
Run Code Online (Sandbox Code Playgroud)
谢谢。
如果我正确地得到了你需要的输出,你可以做这样的事情(我不使用javascript):
ui <- fluidPage(
#give an id to your tab in order to monitor it in the server
tabsetPanel(id = 'tab123',
tabPanel("Panel1", textOutput("PlotPanel1")),
tabPanel("Panel2", textOutput("PlotPanel2"))
)
)
server <- function(input, output) {
#now server can monitor the tabPanel through the id.
#make the observer do whatever you want, e.g. print to a file
observeEvent(input$tab123, {
print(input$tab123)
if (input$tab123 == 'Panel1') {
sink(file = 'c:/Users/TB/Documents/panel1.txt', append = TRUE)
cat(1)
sink()
} else {
sink(file = 'c:/Users/TB/Documents/panel2.txt', append = TRUE)
cat(1)
sink()
}
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
首先,您给您的tabsetPanel. 现在服务器可以访问选项卡数据,您可以使用 创建一个事件来观察observeEvent。每次用户单击每个选项卡时, print 都会在控制台上打印选项卡名称(这是为了让您查看变量input$tab123包含的内容)。然后你就可以用这些信息做任何你想做的事。可以将其存储在带有时间戳的数据库中。在上面的示例中,它在我的文档中创建两个文件,每次有人单击该选项卡时都会写入值 1。然后你只需读入文件并对它们求和即可。
| 归档时间: |
|
| 查看次数: |
353 次 |
| 最近记录: |