Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting to a tab with a button in Shiny

Tags:

redirect

r

shiny

EDIT: code found on internet for updateTabsetPanel

I want to implement a redirect button in my Shiny application but I have never done this before, neither did I found any information on the internet/forum that can lead me into the right direction.

Basically what I am trying to do is the following: I've got a 'Load data' tab and a 'View data' tab, on the 'Load data' tab the user can select data to upload and upload this by pressing on the button "Upload". When this button is clicked, I want the application to redirect the user to the 'View data' tab, where the contents of the data and some other information gets shown.

Here is my UI.R code where the actionButton is located (the call argument):

wellPanel( 
           actionButton(inputId = "load_file", label = "Upload", icon = con("cloud-upload"))
        )

Here is my UI.R code where the tabs are located:

tabSubMenuViewData <-
  tabItem("subMenuViewData", 
          conditionalPanel(
            condition = ("input.load_file > 0"),
            tabsetPanel(type = "tab", id = "tabView",             
                tabPanel("View",DT::dataTableOutput("contents_view")),
                tabPanel("Summary", verbatimTextOutput('XSummary')),
                tabPanel("Structure", verbatimTextOutput('XStructure')),
                tabPanel("Describe", verbatimTextOutput("XDescribe")),
                tabPanel("Pivot",rpivotTableOutput("pivot_2"))     
              )                  

          )
  )

On my server.R code I am thinking in this direction:

observe({
  if (input$load_file > 0)
  updateTabsetPanel(session, "tabView ",selected = "View")
})

Any advice in the right direction is welcome.

Kind regards

like image 215
wbaeckelmans Avatar asked Oct 08 '15 08:10

wbaeckelmans


1 Answers

Solution to my problem, based on Pork Chop's input:

My tabSubMenuViewData was referring to the following UI.R code, where I managed to find my needed parameters.

UI.R code:

dashboardSidebar <- dashboardSidebar(
sidebarMenu(id = "tabs",
  menuItem(tabName = "menuIntro", text = "Intro", icon = icon("sign-in")),
  menuItem(tabName = "menuManageData", text = "Manage data", icon =  icon("share-alt"),
           menuSubItem(tabName = "subMenuLoadData", text = "Load data", icon = icon("cloud-upload")),
           menuSubItem(tabName = "subMenuTransformData", text = "Transform data", icon = icon("pencil")),
           menuSubItem(tabName = "subMenuViewData", text = "View data", icon = icon("search")),
           menuSubItem(tabName = "subMenuSaveData", text = "Save data", icon = icon("cloud-download")), 
           menuSubItem(tabName = "subMenuRemoveData", text = "Remove data", icon = icon("remove")),
           menuSubItem(tabName = "subMenuHistoryData", text = "History", icon = icon("calendar")) 
  ),

Server.R code:

observeEvent(input$load_file, {
  updateTabItems(session, "tabs", "subMenuViewData")
  }
)
like image 125
wbaeckelmans Avatar answered Nov 07 '22 01:11

wbaeckelmans