PaulC91 / shinyauthr

R package with shiny authentication modules
https://paulc91.github.io/shinyauthr/
Other
424 stars 81 forks source link

using shinyauthr with navbarPage #8

Closed Sbirch556 closed 3 years ago

Sbirch556 commented 5 years ago

How would I go about using Shinyauthr with UI elements such as navbarPage, navbarMenu, and tabPanel.

    ui <- shinyUI(

        navbarPage("A Nice Title",

                 navbarMenu("A Menu",

                     tabPanel("With",

                        tabPanel("Tabs"))))

placing the shinyauthr::loginUI between any of these shiny pages, menus, and panels results in nonfunctional outputs.

I've also tried storing the ui in a renderUI function, but the navbarPage does not appear. Is Shinyauthr able to work with these shiny elements, is there a possible workaround?

ChuckHend commented 5 years ago

i haven't tried with login, but maybe something like this would work? swap logout for login, of course.

dashboardPage(

  title = 'My Title',
  skin = 'purple',
  header = dashboardHeader(
                         title ="My Dashboard", 
                         titleWidth = 200, 
                         tags$li(a(div(logoutUI(id = "logout"))),class='dropdown')),
PaulC91 commented 5 years ago

I've posted an example of one possible solution in this gist:

https://gist.github.com/PaulC91/2a1b9ba57a53869ba82093720a9a8fa0

It requires a bit of a javascript hack to get the logout module button up up in the navbar.

Also, all of the menu tabs will be visible prior to login which isn't ideal but you can ensure none of their content is rendered until after a successful login by using req(credentials()$user_auth) inside all the outputs.

GrayAlex49 commented 3 years ago

You can hide and show UI with shinyJS. This works to only show the login page until you've logged in.

https://gist.github.com/GrayAlex49/7631d53af63c9533b70c3bbd48d3584e

PaulC91 commented 3 years ago

Full navbarPage example now in inst/shiny-examples/navbarPage. You can launch it locally with shinyauthr::runNavbarPageExample()