[发光]:在另一个tabPanel中将链接添加到另一个tabPanel [英] [Shiny]: Add link to another tabPanel in another tabPanel

查看:57
本文介绍了[发光]:在另一个tabPanel中将链接添加到另一个tabPanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的首页" tabPanel上建立指向应用程序其他所有tabPanel的链接.

I'm trying to put a link on my "home" tabPanel to all others tabPanels of my app.

想法如下:

ui = navbarPage("",
         tabPanel("home",
                  fluidPage(
                    fluidRow(box("this 1st box should lead me to tab1a")),
                    fluidRow(box("this 2nd box should lead me to tab1b")),
                    fluidRow(box("this 2nd box should lead me to tab2")))
            ),
         navbarMenu("tab1",
                    tabPanel("tab1a"),
                    tabPanel("tab1b")),
         tabPanel("tab2")
         )
shinyApp(ui, server=function(input, output) {})

我在

I've seen the answer in Add link panel tabs in Shiny with various top level navigation bars, but i couldn't implement it on my code, since it deals with html (which i've never worked before, so i'm not familiar with the functions etc) and the code considers paneltabs withing the same tab (not sure if that's why it didn't work here, if maybe it didn't work because the tabs i'm trying to link are on a navbarpage or something).

任何人都可以帮助我,或者告诉我在哪里可以学习如何在示例中实现它吗?

Can anyone help me or tell me where i could learn how to implement this on my example?

推荐答案

我猜这个答案是纯JavaScript编写的,但是非常少.由于Shiny使用随机数ID创建标签,并且不提供对其使用的ID的访问权限,因此必须在客户端进行此操作.但是,没有JavaScript知识可以将其实现到其他方案. JavaScript部分仅用于复制/粘贴,并且触发命令易于理解.

This answer is purely JavaScripted, but very minimal, I guess. Since Shiny creates tabs with random number Ids, and does not give access to the Ids it used, this has do be done client-sided. But there is no knowledge of JavaScript needed to implement this to other scenarios. The JavaScript part is just for Copy/Paste and the trigger command is easy to understand.

我做了什么?我安装了一个函数,该函数找到与所需选项卡相对应的导航栏链接,然后单击它.可以使用"onclick"属性将该实用程序添加到任何元素.不需要特殊标签(例如,不需要"a"标签).

What did I do? I installed a function, that finds the Navbar link corresponding to the desired tab, and just clicks it. This utility can be added to any element with the "onclick" attribute. There are no special tags (e.g. no "a" tag) required.

下面的代码应该可以轻松自定义此解决方案以满足您的需求.

The code below should make it easy to customize this solution to fit your needs.

注意:尽管没有任何视觉效果,我还是将原始代码与box一起使用.

Note: I used the original Code with the box, although it does not have any visual effect.

代码:

library(shiny)
library(shinydashboard)

ui = shinyUI(

  navbarPage("Header",
    tabPanel("home",
      tags$head(tags$script(HTML('
        var fakeClick = function(tabName) {
          var dropdownList = document.getElementsByTagName("a");
          for (var i = 0; i < dropdownList.length; i++) {
            var link = dropdownList[i];
            if(link.getAttribute("data-value") == tabName) {
              link.click();
            };
          }
        };
      '))),
      fluidPage(
        fluidRow(box("this 1st box should lead me to tab1a", onclick = "fakeClick('tab1a')")),
        fluidRow(box("this 2nd box should lead me to tab1b", onclick = "fakeClick('tab1b')")),
        fluidRow(box("this 2nd box should lead me to tab2", onclick = "fakeClick('tab2')"))
      )
    ), 
    navbarMenu("tab1",
      tabPanel("tab1a", "Some Text inside Tab 1a."),
      tabPanel("tab1b", "Some Text inside Tab 1b.")
    ),

    tabPanel("tab2", "Some Text inside Tab 2.")
  )
)

server = function(input, output, session){}

runApp(shinyApp(ui, server), launch.browser = TRUE)

玩得开心!

这篇关于[发光]:在另一个tabPanel中将链接添加到另一个tabPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆