如何访问shinyalerts使用的闪亮标签ID?

如何访问shinyalerts使用的闪亮标签ID?,r,shiny,passwords,shinydashboard,R,Shiny,Passwords,Shinydashboard,我正在尝试为用户设置一个非常基本的块,如果用户不输入密码,他们将无法从tabPanel访问选项卡。为此,我使用了shinyalerts,到目前为止,它作为一个临时密码系统非常有效 但是,当我试图将其设置为观察在我的代码中选择panel_2的事件时,它只会在应用程序的开头弹出。当我点击panel_2时,它确实会响应,但如何让它在我打开应用程序时停止弹出,并且仅当input$tab==“panel_2”为真时 我可以看到observe在server中打印面板id,因此我知道它存在 注意:我使用的是g

我正在尝试为用户设置一个非常基本的块,如果用户不输入密码,他们将无法从
tabPanel
访问选项卡。为此,我使用了
shinyalerts
,到目前为止,它作为一个临时密码系统非常有效

但是,当我试图将其设置为观察在我的代码中选择
panel_2
的事件时,它只会在应用程序的开头弹出。当我点击
panel_2
时,它确实会响应,但如何让它在我打开应用程序时停止弹出,并且仅当
input$tab==“panel_2”
为真时

我可以看到
observe
server
中打印面板id,因此我知道它存在

注意:我使用的是github repo版本的


您需要为您的
观察事件设置
ignoreInit=TRUE

library(shiny)
library(shinyalert)
library(shinydashboardPlus)
library(shinyWidgets)

#password accept function
password_accept = function(x){
  if(x =='1234'){
    shinyalert('Welcome Administrator')
  } else {
    shinyalert("TRY AGAIN", 
               "Enter Password for Admin Access to this Page"
               , type = "input"
               , inputType = "password"
               , time = 0
               #, inputValue = "Enter Password"
               , callbackR = password_accept
    )
  }
}


#example of problem
ui = fluidPage(#useShinyalert(), 
  navbarPage("Sample", 
             id = 'tabs', 
             tabPanel("panel1", useShinydashboardPlus(), 
                      fluidRow(column(9, offset = 1, 
                                      h3(htmlOutput("sample app")))
                      ), 
                      column(4, offset = 5, 
                             boxPlus(solidHeader = T, collapsible = F, collapsed = F, closable = F, title = '', status = 'success', 
                                     uiOutput('fn'), br(), 
                                     uiOutput('ln'), br() 
                             ))
             ), 
             tabPanel("panel2", useShinyalert(), # add shiny alert to act as pwd signin
                      column(6, 
                             fluidRow(
                             ))
             )))


server = (function(input, output, session) {

  #print the tab being accessed
  observe({print(input$tabs)})

  #admin pop up
  observeEvent(input$tabs, 
               {
                 if(input$tabs == 'panel2'){
                   shinyalert("", 
                              "Enter Password for Admin Access to this Page"
                              , type = "input"
                              , inputType = "password"
                              , time = 0
                              #, inputValue = "Enter Password"
                              , callbackR = password_accept
                   )
                 }

               }, ignoreInit = TRUE
  )

  output$fn = renderUI({
    textInput(inputId = "first_name", label = "First Name")
  })

  output$ln = renderUI({
    textInput(inputId = "last_name", label = "Last Name")
  })
})

shinyApp(ui, server)

事实上,我只是重新检查,仍然有一个问题。当我选择panel_2选项卡时,它会调用shinyalert,我可以填写它。但是当我在那之后单击另一个选项卡时,它仍然会调用一个警报。我正在寻找它只弹出当我打开管理选项卡。有什么想法吗?
library(shiny)
library(shinyalert)
library(shinydashboardPlus)
library(shinyWidgets)

#password accept function
password_accept = function(x){
  if(x =='1234'){
    shinyalert('Welcome Administrator')
  } else {
    shinyalert("TRY AGAIN", 
               "Enter Password for Admin Access to this Page"
               , type = "input"
               , inputType = "password"
               , time = 0
               #, inputValue = "Enter Password"
               , callbackR = password_accept
    )
  }
}


#example of problem
ui = fluidPage(#useShinyalert(), 
  navbarPage("Sample", 
             id = 'tabs', 
             tabPanel("panel1", useShinydashboardPlus(), 
                      fluidRow(column(9, offset = 1, 
                                      h3(htmlOutput("sample app")))
                      ), 
                      column(4, offset = 5, 
                             boxPlus(solidHeader = T, collapsible = F, collapsed = F, closable = F, title = '', status = 'success', 
                                     uiOutput('fn'), br(), 
                                     uiOutput('ln'), br() 
                             ))
             ), 
             tabPanel("panel2", useShinyalert(), # add shiny alert to act as pwd signin
                      column(6, 
                             fluidRow(
                             ))
             )))


server = (function(input, output, session) {

  #print the tab being accessed
  observe({print(input$tabs)})

  #admin pop up
  observeEvent(input$tabs, 
               {
                 if(input$tabs == 'panel2'){
                   shinyalert("", 
                              "Enter Password for Admin Access to this Page"
                              , type = "input"
                              , inputType = "password"
                              , time = 0
                              #, inputValue = "Enter Password"
                              , callbackR = password_accept
                   )
                 }

               }, ignoreInit = TRUE
  )

  output$fn = renderUI({
    textInput(inputId = "first_name", label = "First Name")
  })

  output$ln = renderUI({
    textInput(inputId = "last_name", label = "Last Name")
  })
})

shinyApp(ui, server)