首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >闪亮的tabPanel和

闪亮的tabPanel和
EN

Stack Overflow用户
提问于 2015-01-30 09:09:03
回答 2查看 549关注 0票数 7

我已经阅读了伟大的教程这里。然而,我对jQuery的了解等于零。我在ShinyApp中使用了几个ShinyApp来显示数据。本教程解释了如何跟踪链接点击事件(这很好,我包括了一个.js在教程中解释)。是否有一种方法可以跟踪用户是否单击特定的tabPanel (例如Panel1Panel2)?我也试图对引用外部源的链接进行同样的操作,但这是行不通的。

代码语言:javascript
复制
tabsetPanel(
tabPanel("Panel1", showOutput("PlotPanel1", 'dimple')),
tabPanel("Panel2", showOutput("PlotPanel2", 'dimple')))

编辑:

我想我必须在我的analytics.js文件中包含一些代码。因此,我尝试了几件事,但坦率地说,不了解jQuery,这是错误的。这里有人能帮忙吗?

代码语言:javascript
复制
$( ".selector" ).tabs({
  on('option', 'click', function(l) {
  ga('send', 'event', 'tabPanel', 'tabPanel', $(l.currentTarget).val());
  }
});

谢谢。

EN

回答 2

Stack Overflow用户

发布于 2019-06-17 14:02:56

如果我正确地获得了作为输出所需的内容,您可以这样做(我不使用javascript):

代码语言: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) 

首先,你给你的tabsetPanel一个id。现在服务器可以访问选项卡数据,您可以使用observeEvent创建要观察的事件。每次用户单击每个选项卡时,print都会在控制台上打印选项卡名(这是供您查看变量input$tab123包含的内容)。那么你可以用这些信息做任何你想做的事。可能,将其存储在带有时间戳的数据库中。在上面的示例中,它在文档中创建两个文件,每次有人单击选项卡时都会写入值1。然后你就把文件读进去,把那些文件加起来。

票数 2
EN

Stack Overflow用户

发布于 2021-01-15 01:38:53

在尝试了这么多不同的方法之后,这个方法对我有用:

代码语言:javascript
复制
$(document).on('click', 'a', function(e) {
    ga('send', 'event', 'TabsetPanel', 'Tab Viewed', $(this).attr('data-value'));
  });

虽然它将收集与a相关的所有事件,但我想只有选项卡有数据值,其余的将显示为not设置。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28232499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档