How to create a login page?

The goal is to have a shiny module ui1.Rthat loads the second module ui2.Rat the click of a button confirm. I think the problem is that it is is.null(input$confirm)always invalid. Instead, I need to invalidate the expression only after clicking confirm. The question is very close to Starting the Shiny application after entering the password , but I'm trying to execute a modular solution.

ui.R

library(shiny)
library(shinyjs)
htmlOutput("page")

server.R

rm(list = ls())
library(shiny)
library(dplyr)
library(shinyjs)
Logged <-  FALSE

shinyServer(function(input, output) {

  source('ui1.R') #login page
  source('ui2.R')


  observeEvent(!is.null(input$confirm), {
    Logged <<- T
  })

  observe({
    if (Logged == FALSE) {
      output$page <- renderUI({ 
        ui1Output('ui1Output') 
      })
      output$lsuId <- renderText({ input$lsuId })
    }
    if (Logged == TRUE) 
    {
      output$page <- renderUI({ ui2 })
    }
  })
  callModule(ui1,'ui1') 
})

ui1.R

library(shinyjs)

ui1Output <-  function(id, label = "ui1") {
  ns <- NS(id)
  shinyUI(fluidPage(
    useShinyjs(),
    titlePanel("Form"),
    div(textInput(ns("lsuId"), "This has to be filled", ""),
      actionButton(ns("confirm"), "Submit", class = "btn-primary")
    )
  ))
}

ui1 <- function(input, output, session) {
  observe({
    LSUID <- reactive({ input$lsuId })
    shinyjs::toggleState(id = "confirm", condition = LSUID())
  })
}

ui2.R

ui2<-  shinyUI(fluidPage(
 div("well done!")
))

global.R

source('ui1.R') #login page
source('ui2.R')
+4
source share
1 answer

I think you have two questions:

First, your confirmation button value is saved: input$"ui1Output-confirm"and not here:input$confirm

I would suggest replacing:

observeEvent(is.null(input$confirm), {
  Logged <<- F
})

By:

observeEvent(input$"ui1Output-confirm", {
    Logged <<- T
})

, , . , :

tmp <- input$"ui1Output-confirm"

:

observe({
    tmp <- input$"ui1Output-confirm"

    if (Logged == FALSE) {
        output$page <- renderUI({ 
            ui1Output('ui1Output') 
        })
        output$lsuId <- renderText({ input$lsuId })
    }
    if (Logged == TRUE) 
    {
         output$page <- renderUI({ ui2 })
    }
})
+2

Source: https://habr.com/ru/post/1648981/


All Articles