The updateTabsetPanel does not work.

Asked 2 years ago, Updated 2 years ago, 47 views

I have a question about Shiny.
If you put in search criteria and get the result, I want to switch tab to the table in the data display and display it.
However, the updateTabsetPanel does not work.
Please let me know if there is a problem.

Server.R to

shinyServer(function(input,output){

  callModule(tab_search, id="tab_search")

})

This is the module that was created.

################################################################################
#the layout for tab search item
#Parameter: p_shipment
#           p_product
tab_searchUI <- function(id, tab_name,p_shipment,p_product,p_duration) {
  ns <- NS(id)
  tabItem(tabName = tab_name,
    sidebarLayout(
      sidebarPanel(
        #Set the search condition here.
        #The first search key is duration.
        dateRangeInput(inputId = ns("i_dates"), label = "Duration"),
        #The second search key is shipments
        selectizeInput(
          inputId = ns("i_shipment"), label = "Shipment", choices = state.name, multiple = TRUE
        ),
        #The third search key is data products
        selectInput(
          inputId=ns("i_product"), label="Product", choices=state.name, multiple=TRUE
        ),

        # The search button
        actionButton(inputId=ns("b_srh"), label="Search")
      ),

      # Output the search result.
      mainPanel(
          tabsetPanel(type="tabs", 
                      id=ns("srh_tabs"),
                      tabPanel("Search", 
                               h2("Search result is show here.", align="center"),
                               br(),
                               div(img(src="bigorb.png"), align="center") ,
                      tabPanel("Table", tableOutput(ns("table")),
                      tabPanel("Summary", verbbatimTextOutput(ns("summary")),
                      tabPanel("Plot",plotOutput(ns("Plot"))
        )
      )
    )
  )
}

################################################################################
# Server side corresponding the tab of tab_searchUI
# Notice the function name is pending with corresponding UI
#
tab_search<-function(input, output, session){


  srhresult<-NULL
  ltabs<- NULL
  stub<-NULL
# The case to use event reactive function for getting the event of a button.
  reactive_data<- eventReactive(input$b_srh,{
    # Set the search result 
    ltabs<-session$ns("srh_tabs")
    stub<-session$ns("table")
    print( paste("tabset name is",ltabs,">>")
    print(paste("tab name is",stab,">>")
    g_Search_rlt <<-srhresult
    srhresult<-pistonrings
  })
  output $table<-renderTable(reactive_data())

  # Change the tab to table

  observeEvent(input$b_srh, {
    print(session$ns("srh_tabs"))
    print(session$ns("table"))
    updateTabsetPanel(session, paste(session$ns("srh_tabs")),
                      selected = paste(session$ns("table"))
    )
    #     output$caption<-renderText(paste(l_caption(), "case2"))
   })
}

r

2022-09-30 18:01

1 Answers

First, if you use updateTabsetPanel, you must specify value for tabset.

tabPanel("Table", tableOutput(ns("table")), value=ns("table"))

Then, if you are using a ShinyModule, you must pass the correct session.
In this case, the parent session.

tab_search<-function(input, output, session, parentSession) {#edit
  # (Omitted)

  # Change the tab to table

  observeEvent(input$b_srh, {
    updateTabsetPanel(parentSession, session$ns("srh_tabs"), #edit
                      selected = session $ns("table")
    )
  })
}

server<-function(input, output, session){
  callModule(tab_search, id="tab_search", session)#edit
}


2022-09-30 18:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.