Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use tabPanel as input in R Shiny?

Tags:

r

shiny

Is it possible to perform an action if the user clicks into a particular tabPanel?

For instance, if the user clicks into tabPanel("A", ...) then display a popup saying You are viewing tab "A".

like image 857
mchen Avatar asked Apr 23 '14 11:04

mchen


People also ask

What is Tabpanel in shiny?

Tab PanelsEach tab panel is provided a list of output elements which are rendered vertically within the tab. In this example we added a summary and table view of the data to the Hello Shiny app, each rendered on their own tab.

Which function is used to add a shiny server component Tabpanel ()?

shinyApp. Finally, we use the shinyApp function to create a Shiny app object from the UI/server pair that we defined above.


1 Answers

tabsetPanel() will return the value assigned to the active tabPanel(). If you just want to update another output you could do something like this:

ui.R

library(shiny)      shinyUI(basicPage(     textOutput("text"),       tabsetPanel(id = "tabs",           tabPanel("Tab A", value = "A", "This is Tab A content"),           tabPanel("Tab B", value = "B", "Here's some content for tab B.")   )  )) 

server.R

library(shiny)  shinyServer(function(input, output) {      output$text <- renderText({paste0("You are viewing tab \"", input$tabs, "\"")})  }) 

but something more complicated like creating a popup would probably require making an observer and some additional custom coding...

like image 143
Eric Avatar answered Sep 29 '22 18:09

Eric