闪亮:单击图像时更改选项卡 [英] shiny:change tab when click on image

查看:54
本文介绍了闪亮:单击图像时更改选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Shiny应用程序,我的一些用户(对这种布局不太熟悉)不了解该应用程序可以使用选项卡,而且他们只是看不到主页的位置.

I'm building a Shiny application and some of my users (not very familiar with this kind of layout) don't understand that the application works with tabs and they just don't see where to go from the Homepage.

这就是为什么我要在主页上显示较大的图像,并且当他们单击它时,它会自动激活第二个选项卡.我知道如何将链接添加到图像:

That's why I want to display a big infography on the main page, and when they click on it, it automatically activates the second tab. I know how to add a link to an image:

tags(a(img(src="image.png"), href="link.com"))

我知道如何以编程方式选择其他标签:

And I know how to programmatically select a different tab:

updateTabsetPanel(session, inputId="navbar", selected="tab2")

但是如何结合这两个动作? 谢谢,

But how to combine those 2 actions? Thanks,

推荐答案

您可以为图像提供id,并使用

You can give the image an id, and use the onclick() function from shinyjs. Working example:

require(shiny)
require(shinyjs)


ui <- fluidPage(
  img(id="my_img",src="image.png",style="cursor:pointer;"),
  useShinyjs(),
  tabsetPanel(id="navbar",
              tabPanel("tab1", p("This is tab 1")),
              tabPanel("tab2", p("This is tab 2"))
  )
)



server <- function(input, output,session){

  shinyjs::onclick("my_img",  updateTabsetPanel(session, inputId="navbar", selected="tab2"))

}

shinyApp(ui,server)

希望这会有所帮助!

这篇关于闪亮:单击图像时更改选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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