If语句在闪亮的应用程序中连续两次无法运行

问题描述 投票:1回答:1

我有一个显示3个标签的闪亮应用。

Documents选项卡中有一个表。当用户单击第一行的setosa时,他将移至View选项卡(仅在单击时可见),并看到一个表格。当用户单击第二行的setosa时,他将移至View选项卡并看到另一个表。另外,这些表必须仅在View选项卡上可见。

[该应用似乎运行正常,但是如果我单击第一行setosa,请移至View选项卡,再次返回Documents选项卡,然后尝试再次单击第一行setosa,则不会发生任何事情。我必须单击第二行setosa以使其再次起作用。第二行setosa也是如此。

简而言之,我不能连续两次执行相同的操作,并且我认为我的if条件对此负责。

library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(shinydashboardPlus)
library(DT)
library(shinyjs)

shinyApp(
  ui = dashboardPagePlus(
    header = dashboardHeaderPlus(title = span(strong("ArmorDoc"),style = "color: black;")

    ),
    sidebar = dashboardSidebar(

    ),
    body = dashboardBody(

      useShinyjs(),
      tags$hr(),
      tabsetPanel(
        id ="tabA",
        type = "tabs",
        tabPanel("Documents",icon = icon("accusoft"),
                 tags$hr(),
                 DTOutput("dt1")),
        tabPanel("View", icon = icon("table"),
                 DTOutput("dt3")
        ),
        tabPanel("Upload", icon = icon("table")

        )

      )

    )),
  server = function(input, output,session) {
    observeEvent(input$tabA, {
      if(input$tabA == "Documents"|input$tabA=="Upload"){
        hideTab("tabA", "View")
      }
    })



    observeEvent(input$dt1_cell_clicked, {
      # alternative: input$dt1_cells_selected
      if (req(input$dt1_cell_clicked$value) == "setosa") {
        showTab("tabA", "View")
        updateTabsetPanel(session, inputId = "tabA", selected = "View")
      }
    })

    output$dt1 <- DT::renderDataTable({
      DT::datatable(
        iris[1:2,],
        filter = "top",
        options = list(searchHighlight = TRUE, search = list(search = ""),pageLength = 5,columnDefs = list(list(className = 'dt-left', targets = "_all"))),rownames= FALSE,
        selection = list(mode = 'single', target = 'cell')
      ) 

    })


    output$dt3 <- renderDT(server = F,
                           if(input$dt1_cell_clicked$row == 1&input$tabA=="View"){

                             datatable(iris)
                           }
                           else if(input$dt1_cell_clicked$row == 2&input$tabA=="View"){
                             datatable(mtcars)
                           }
                           else{
                             return(NULL)
                           }
    )


  }
)
r shiny dt
1个回答
0
投票

可以找到答案here。与Proxy中的observeEvent()方法相同。

© www.soinside.com 2019 - 2024. All rights reserved.