datastorm-open / shinymanager

Simple and secure authentification mechanism for single shiny applications.
https://datastorm-open.github.io/shinymanager/
381 stars 79 forks source link

Its possible to add a "sub-panel" with shiny manager? #116

Closed Jorge-hercas closed 2 years ago

Jorge-hercas commented 3 years ago

I am working on a dashboard app, but I would like to know if it is possible for the app to ask for authentication in a specific tab panel. I tried to do something like that but I can't get it to work, do you know if it's possible with shinymanager or with conditionals?

The code im testing is the following:

`if (interactive()) { library(shiny) library(bs4Dash) library(shinymanager)

credentials <- data.frame( user = c("shiny", "shinymanager"), password = c("azerty", "12345"), stringsAsFactors = FALSE )

shinyApp( ui = bs4DashPage( sidebar_collapsed = TRUE, controlbar_collapsed = TRUE, enable_preloader = FALSE, loading_duration = 2, navbar = bs4DashNavbar(skin = "dark"), body = bs4DashBody( bs4TabItems( bs4TabItem( tabName = "tab1", p("xd") ) ) ), sidebar = bs4DashSidebar( skin = "dark", bs4SidebarMenu( id = "test", bs4SidebarMenuItem( tabName = "tab1", text = "Tab 1" ), secure_app(bs4SidebarMenuItem( tabName = "tab2", text = "Tab 2" )), bs4SidebarMenuItem( text = "Click me pleaaaaase", bs4SidebarMenuSubItem( tabName = "subtab1", text = "Tab 3" ),bs4SidebarMenuSubItem( tabName = "subtab2", text = "Tab 4" ) ) ) ), controlbar = bs4DashControlbar(skin = "light"), footer = bs4DashFooter() ), server = function(input, output, session) {

  res_auth <- secure_server(
    check_credentials = check_credentials(credentials)
  )

  observeEvent(input$test, {
    if (input$test == "subtab1") {
      showModal(modalDialog(
        title = "Thank you so much",
        "You clicked me! This event is the result of
       an input bound to the menu. By adding an id to the
       bs4SidebarMenu, input$id will give the currently selected
       tab. This is useful to trigger some events.",
        easyClose = TRUE,
        footer = NULL
      ))
    }
  })
}

) }`

pvictor commented 2 years ago

No you cannot use secure_app() like that, secure_app() is intended to be used with the whole application. However you could use auth_ui() / auth_server() module inside a tab, but it will not be as secure as using secure_app(). An alternative will be to creating roles and creating the tab (or tab's content) only for people with permission.