Coder Social home page Coder Social logo

Comments (2)

JohnCoene avatar JohnCoene commented on August 21, 2024 1

It's a great solution but it works.

library(shiny)
library(firebase)

ui <- fluidPage(
  useFirebase(),
  tags$head(
    tags$script(
      # ui must be present at launch so we leave it there but hide it
      HTML(
        "Shiny.addCustomMessageHandler('show-login', (msg) => {
          $('#ui-wrapper').show();
        })"
      )
    )
  ),
  div(
    id = "ui-wrapper",
    style = "display: none;",
    firebaseUIContainer()
  ),
  reqSignin(actionButton("signout", "Sign out")),
  uiOutput("msg"),
  plotOutput("plot")
)

server <- function(input, output, session){
  f <- FirebaseUI$
    new("local")$
    set_providers(
      email = TRUE,
      yahoo = TRUE,
      google = TRUE,
      github = TRUE,
      twitter = TRUE,
      facebook = TRUE,
      microsoft = TRUE
    )$
    launch()

  output$plot <- renderPlot({
    f$req_sign_in() # require sign in
    plot(cars)
  })

  # Sign in runs twice hence this check
  ran <- 0L
  observe({
    user <- f$get_signed_in() # get logged in user info

    ran <<- ran + 1L

    if(ran < 2L)
      return()

    if(is.null(user))
      session$sendCustomMessage("show-login", list())
  })

  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)

from firebase.

HugoGit39 avatar HugoGit39 commented on August 21, 2024

SUPER! Works! Thank you so much!

from firebase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.