0

im trying to invoke js across different tabs in shiny like the code below

library(shiny)
library(shinyjs)

ui <- tagList(
  useShinyjs(),
   navbarPage(
   "shinyjs with navbarPage",
   tabPanel("tab1",
         actionLink(inputId = 'link',label = 'Fast Forward')
         ),
 tabPanel("tab2",
         actionButton("button", "Click me"),
         textInput(inputId = "hello", label='',value = "Hello!")
         )
 )
)

server <- function(input, output, session) {
  observeEvent(input$link, {
  runjs('$("#link").click();')
})

observeEvent(input$button,{
  toggle("hello")
})
}

shinyApp(ui, server)

the command is not going through, what could be the problem?

yonicd
  • 498
  • 1
  • 4
  • 15

2 Answers2

0

Try with this modified server part:

server <- function(input, output, session) {
            observeEvent(input$link, {
                    runjs("$('a[data-value=\"tab2\"]').tab('show');")

            })

            observeEvent(input$button,{
                    toggle("hello")
            })
    }
Valter Beaković
  • 3,140
  • 2
  • 20
  • 30
0

i found the mistake.

i wrote

runjs('$("#link").click();') 

instead of

runjs('$("#button").click();')
yonicd
  • 498
  • 1
  • 4
  • 15