shinjs::show() 在 shinyjs::hide() 之后不显示元素

shinjs::show() not showing element after shinyjs::hide()

我有一个闪亮的仪表板,我正在尝试使用操作按钮 select 通过要显示的内容而不是菜单选项卡。我有它 built 这样当你点击分配给一个特定 fluid 行的操作按钮时它会隐藏其他选项卡,但我似乎无法让它带来 fl uid 向后排。我正在使用 shinyjs showhide 函数。

这是我 ui

中的代码
    dashboardBody(
     tags$head(
       tags$link(
         rel = "stylesheet",
         type = "text/css",
         href = "datainstate_style.css")
     ),
     useShinyjs(),
     introjsUI(),

 # MAIN BODY ---------------------------------------------------------------- 

     fluidRow(
       column(
         width = 12,
           bsButton("VsOpponent", 
                    label = "Vs Opponent", 
                    icon = icon("users"), 
                    style = "success"),
           bsButton("trendsinperformance", 
                    label = "Trends", 
                    icon = icon("digital-tachograph"), 
                    style = "success"),
           bsButton("lineupsandchampions", 
                    label = "Lineups and Champions", 
                    icon = icon("child"), 
                    style = "success")
       )
    ),

    fluidRow(
      div( id = "VsOpponent_panel",
        column(
          width = 12,
          gt_output("opponents_table")
        ),
        column(
          width = 12,
          plotOutput("radar_plot")
        ),
        column(
          width = 12,
          plotOutput("gold_plot")
        )
      )
     ),
 fluidRow(
   div( id = "trendsinperformance_panel",
     column(
       width = 12,
       plotOutput("gold")
     )
   )
 ),

 fluidRow(
   div( id = "lineupsandchampions_panel",
     column(
       width = 12,
       textOutput("test")
     )
   )
 )
   
  )

然后下面是我服务器中对应的代码

  ## Determine which panel to show
  observeEvent("", {
    show("VsOpponent_panel")
    hide("lineupsandchampions_panel")
    hide("trendsinperformance_panel")
  }, once = TRUE)
  observeEvent(input$VsOpponent, {
    show("VsOpponent_panel")
    hide("lineupsandchampions_panel")
    hide("trendsinperformance_panel")
  })
  observeEvent(input$trendsinperformance, {
    show("trendsinperformance_panel")
    hide("lineupsandchampions_panel")
    hide("VsOpponent_panel")
  })
  observeEvent(input$lineupsandchampions, {
    show("lineupsandchampions_panel")
    hide("trendsinperformance_panel")
    hide("VsOpponent_panel")
  })

感谢您的帮助!

嗯,这些按钮似乎对我有用,请先尝试 hide divs 然后 show 其他

library(shiny)
library(shinyjs)
library(shinyBS)

ui <- fluidPage(
    useShinyjs(),
    fluidRow(
        column(
            width = 4,
            bsButton("VsOpponent", 
                     label = "Vs Opponent", 
                     icon = icon("users"), 
                     style = "success"),
            bsButton("trendsinperformance", 
                     label = "Trends", 
                     icon = icon("digital-tachograph"), 
                     style = "success"),
            bsButton("lineupsandchampions", 
                     label = "Lineups and Champions", 
                     icon = icon("child"), 
                     style = "success")
        )
    ),
    
    fluidRow(
        div(id = "VsOpponent_panel",
             column(
                 width = 4,
                 plotOutput("p1")
             ),
             column(
                 width = 4,
                 plotOutput("p2")
             ),
             column(
                 width = 4,
                 plotOutput("p3")
             )
        )
    ),
    fluidRow(
        div( id = "trendsinperformance_panel",
             column(
                 width = 4,
                 plotOutput("p4")
             )
        )
    ),
    
    fluidRow(
        div( id = "lineupsandchampions_panel",
             column(
                 width = 4,
                 plotOutput("p5")
             )
        )
    )
)

server <- function(input, output, session) {
    
    output$p1 <- renderPlot({plot(runif(10),main = "Plot1")})
    output$p2 <- renderPlot({plot(runif(10),main = "Plot2")})
    output$p3 <- renderPlot({plot(runif(10),main = "Plot3")})
    output$p4 <- renderPlot({plot(runif(10),main = "Plot4")})
    output$p5 <- renderPlot({plot(runif(10),main = "Plot5")})

    
    ## Determine which panel to show
    observeEvent("", {
        hide("lineupsandchampions_panel")
        hide("trendsinperformance_panel")
        show("VsOpponent_panel")
    }, once = TRUE)
    
    observeEvent(input$VsOpponent, {
        hide("lineupsandchampions_panel")
        hide("trendsinperformance_panel")
        show("VsOpponent_panel")
    })
    
    observeEvent(input$trendsinperformance, {
        hide("lineupsandchampions_panel")
        hide("VsOpponent_panel")
        show("trendsinperformance_panel")
    })
    
    observeEvent(input$lineupsandchampions, {
        hide("trendsinperformance_panel")
        hide("VsOpponent_panel")
        show("lineupsandchampions_panel")
    })
    
}

shinyApp(ui, server)