Shiny 获取活动选项卡名
我想获取活动选项卡名。我知道可以在侧边栏菜单中使用id参数,然后在服务器中使用input$id调用它。我无法使用此功能,因为我有自定义的边栏,它不返回所选(或活动)选项卡名称。因此,我想用javascript解决这个问题。我用JS试过了Shiny 获取活动选项卡名,shiny,shinyjs,Shiny,Shinyjs,我想获取活动选项卡名。我知道可以在侧边栏菜单中使用id参数,然后在服务器中使用input$id调用它。我无法使用此功能,因为我有自定义的边栏,它不返回所选(或活动)选项卡名称。因此,我想用javascript解决这个问题。我用JS试过了 $('.tab content').find('.active').attr('data-value')但它工作不正常 library(shiny) library(shinydashboard) library(shinyjs) jscode <-
$('.tab content').find('.active').attr('data-value')
但它工作不正常
library(shiny)
library(shinydashboard)
library(shinyjs)
jscode <- "shinyjs.gettab = function () {
$('.tab-content').find('.active').attr('data-value')
}"
ui <- dashboardPage(
dashboardHeader(title = "Basic Use of JS"),
dashboardSidebar(
sidebarMenu(
menuItem(
text = "HOME",
tabName = "home",
icon = icon("home")
),
menuItem(
text = "MAP",
tabName = "map",
icon = icon("map")
)
)),
dashboardBody(
useShinyjs(),
extendShinyjs(text = jscode)
))
server = function(input, output) {
observe({ print(js$gettab()) })
}
runApp(list(ui = ui, server = server), launch.browser =T)
库(闪亮)
图书馆(shinydashboard)
图书馆(shinyjs)
jscode