gpt4 book ai didi

r - 禁止在选项卡之间行走 Shiny

转载 作者:行者123 更新时间:2023-12-01 04:31:48 25 4
gpt4 key购买 nike

我有几个选项卡的 Shiny 应用程序。问题是我想用按钮在选项卡之间移动,而不是通过单击选项卡。我如何禁止点击选项卡?代码的小例子:

ui <- navbarPage('Test App', id = "inTabset",
tabPanel(title = "Panel 1", value = "panel1",
actionButton('jumpToP2', 'Jump to Secon Tab')),
tabPanel(title = "Panel 2", value = "panel2",
actionButton('jumpToP1', 'Jump to First Tab'))
)

server <- function(input, output, session) {
observeEvent(input$jumpToP2, {
updateTabsetPanel(session, "inTabset",
selected = "panel2")
})

observeEvent(input$jumpToP1, {
updateTabsetPanel(session, "inTabset",
selected = "panel1")
})

}

shinyApp(ui, server)

最佳答案

这是一个可能的解决方法。我们可以使用 shinyjs 禁用 navbar 按钮,并添加一些 CSS 将光标悬停在导航栏上时将光标更改为默认值。

可能有我不知道的更简单的方法,所以我很想看看其他可能的解决方法:)希望这有帮助!

library(shiny)
library(shinyjs)

ui <- navbarPage('Test App', id = "inTabset",
tabPanel(title = "Panel 1", value = "panel1",
actionButton('jumpToP2', 'Jump to Secon Tab')),
tabPanel(title = "Panel 2", value = "panel2",
actionButton('jumpToP1', 'Jump to First Tab')),
useShinyjs(),
tags$head(tags$style(HTML('.navbar-nav a {cursor: default}')))
)

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

shinyjs::disable(selector = '.navbar-nav a')

observeEvent(input$jumpToP2, {
updateTabsetPanel(session, "inTabset",
selected = "panel2")
})

observeEvent(input$jumpToP1, {
updateTabsetPanel(session, "inTabset",
selected = "panel1")
})

}

shinyApp(ui, server)

关于r - 禁止在选项卡之间行走 Shiny ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49314658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com