0

Bellow is my code: I need to click on image 1 change to tabpanel 1, when I click on image 2 tabpanel 2 is selected, clicking on image 3 tabpanel 3 is selected and so on...

ui <- fluidPage(
  img(id="my_img1",src="img/hexsticker.png",style="cursor:pointer;", value  = 1),
  img(id="my_img2",src="img/hexsticker.png",style="cursor:pointer;", value  = 2),
  div(style = 'display: flex; gap: 5em; width: 500px; justify-content: space-between;',
  tabsetPanel(id="navbar1",
              tabPanel("tab1", p("This is tab 1"), value = 1),
              tabPanel("tab2", p("This is tab 2"), value = 2)
  )
  )
  
)



server <- function(input, output,session){
  
  observeEvent(input$my_img1,
               {
                 updateTabsetPanel(session,
                                   inputId = 'navbar1',
                                   selected = input$navbar1)
                 
               })
}

shinyApp(ui,server)

I know that I can do this with shinyjs package but I need to do this with basic shiny's. Is it possible?

Laura
  • 675
  • 10
  • 32
  • Try the answer [here](https://stackoverflow.com/questions/51525087/handling-image-map-clicks-in-a-shiny-app) – YBS Dec 24 '22 at 17:26
  • @YBS thanks for your time. yes I understand, but uses javascript. I have to study js. But using only shiny is not possible? – Laura Dec 24 '22 at 19:21
  • You should try to use `imageOutput` and the `clickId` option for each image and then identify the image clicked as shown in the example [here](https://shiny.rstudio.com/reference/shiny/1.4.0/plotoutput) – YBS Dec 24 '22 at 21:33

0 Answers0