1

Shinyに関する質問です。
検索条件を入れて、検索してその結果が得た場合、tabをデータ表示のtableに切り替えて表示したい。
しかし、updateTabsetPanelは動かない。
なにか問題か教えてほしいです。

Server.Rから

shinyServer(function(input, output) {

  callModule(tab_search,id = "tab_search")

})

ここは作成されたモジュールです。

################################################################################
#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
        selectizeInput(
          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 shown here.",align = "center"),
                               br(),
                               div(img(src="bigorb.png"),align="center")),
                      tabPanel("Table", tableOutput(ns("table"))),
                      tabPanel("Summary", verbatimTextOutput(ns("summary"))),
                      tabPanel("Plot", plotOutput(ns("plot")))
        )
      )
    )
  )
}

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


  srhresult <- NULL
  ltabs <- NULL
  stab <- NULL
# the case to use eventreactive function for getting the event of a button.
  reactive_data <- eventReactive(input$b_srh, {
    #Set the search result 
    ltabs <-  session$ns("srh_tabs")
    stab <- 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(),"case 2"))
   })
}

1 件の回答 1

1

まず、 updateTabsetPanel を使う場合、 tabsetvalue を指定する必要があります。

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

次に、ShinyModuleを使用している場合、正しい session を渡す必要があります。
この場合、親の session です。

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

  #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
}

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。