firebase icon indicating copy to clipboard operation
firebase copied to clipboard

How should firebase be integrated with a shinydashboard app?

Open paladinic opened this issue 2 years ago • 2 comments

Hi,

I am trying to use the firebase lib in a shiny app built using shinydashboard. I tried adjusting the example provided in the documentation but I don't think this is the correct way of doing this. Is there a suggested way to integrate the two libs?


library(shiny)
library(shinydashboard)
library(firebase)

ui <- dashboardPage(
  header = dashboardHeader(title = 'title'),
  sidebar = dashboardSidebar(),
  body = dashboardBody(
    useFirebase(),
    firebaseUIContainer(),
    reqSignin(actionButton("signout", "Sign out")),
    uiOutput("msg"),
    plotOutput("plot")
  )
)

server <- function(input, output){
  f <- FirebaseUI$
    new("session")$
    set_providers(
      email = TRUE,
      google = TRUE
    )$
    launch()
  
  output$plot <- renderPlot({
    f$req_sign_in() # require sign in
    plot(cars)
  })
  
  output$msg <- renderUI({
    f$req_sign_in() # require sign in
    
    user <- f$get_signed_in() # get logged in user info
    print(user)
    
    h4("Welcome,", user$response$displayName)
  })
  
  observeEvent(input$signout, {
    f$sign_out()
  })
  
}

shinyApp(ui, server)

paladinic avatar Oct 17 '22 11:10 paladinic

Worked for me aft CTRL + SHIFT + R

JohnCoene avatar Oct 17 '22 14:10 JohnCoene

I was wondering if there is a right way to do this, especially when it comes to dealing with multiple tabs. The example below expands a bit on that showing how I though this could be implemented.

library(shiny)
library(shinydashboard)
library(firebase)

ui <- dashboardPage(
  header = dashboardHeader(title = 'title'),
  sidebar = dashboardSidebar(sidebarMenu(
    menuItem(
      "login",
      tabName = "login",
      icon = icon(lib = 'glyphicon', "th")
    ),
    menuItem(
      "start",
      tabName = "start",
      icon = icon(lib = 'glyphicon', "th")
    )
  )),
  body = dashboardBody(
    useFirebase(),
    firebaseUIContainer(),
    tabItems(
      tabItem(tabName = 'login',reqSignin(actionButton("signout", "Sign out"))),
      tabItem(
        tabName = 'start',
        plotOutput("plot")
      )
    )
  )
)

server <- function(input, output) {
  f <- FirebaseUI$new("session")$set_providers(email = TRUE,
                                               google = TRUE)$launch()
  
  output$plot <- renderPlot({
    f$req_sign_in() 
    plot(cars)
  })

  observeEvent(input$signout, {
    f$sign_out()
  })
  
}

shinyApp(ui, server)

paladinic avatar Oct 17 '22 15:10 paladinic

See https://github.com/JohnCoene/firebase/issues/5 there isn't a nice elegant solution currently

JohnCoene avatar Oct 21 '22 09:10 JohnCoene