if (interactive()) {
# global authentication
library(shiny)
library(shinyMobile)
shinyApp(
ui = f7Page(
title = "Login module",
f7SingleLayout(
navbar = f7Navbar(
title = "Login Example",
hairline = FALSE,
shadow = TRUE
),
toolbar = f7Toolbar(
position = "bottom",
f7Link(label = "Link 1", href = "https://www.google.com"),
f7Link(label = "Link 2", href = "https://www.google.com")
),
f7Login(id = "loginPage", title = "Welcome"),
# main content
f7BlockTitle(
title = HTML(paste("Welcome", textOutput("user"))),
size = "large"
) %>% f7Align("center")
)
),
server = function(input, output, session) {
loginData <- callModule(f7LoginServer, id = "loginPage")
output$user <- renderText({
req(loginData$user)
loginData$user()
})
}
)
# section specific authentication
library(shiny)
library(shinyMobile)
shinyApp(
ui = f7Page(
title = "Local access restriction",
f7TabLayout(
navbar = f7Navbar(
title = "Login Example for Specific Section",
hairline = FALSE,
shadow = TRUE
),
f7Tabs(
id = "tabs",
f7Tab(
tabName = "Tab 1",
"Without authentication"
),
f7Tab(
tabName = "Restricted",
# main content
f7BlockTitle(
title = HTML(paste("Welcome", textOutput("user"))),
size = "large"
) %>% f7Align("center")
)
),
f7Login(id = "loginPage", title = "Welcome", startOpen = FALSE)
)
),
server = function(input, output, session) {
# trigger
trigger <- reactive({
req(input$tabs)
})
# do not run first since the login page is not yet visible
loginData <- callModule(
f7LoginServer,
id = "loginPage",
ignoreInit = TRUE,
trigger = trigger
)
output$user <- renderText({
req(loginData$user)
loginData$user()
})
}
)
# with 2 different protected sections
library(shiny)
library(shinyMobile)
shinyApp(
ui = f7Page(
title = "Multiple restricted areas",
f7TabLayout(
navbar = f7Navbar(
title = "Login Example for 2 Specific Section",
hairline = FALSE,
shadow = TRUE
),
f7Tabs(
id = "tabs",
f7Tab(
tabName = "Tab 1",
"Without authentication"
),
f7Tab(
tabName = "Restricted",
# main content
f7BlockTitle(
title = "1st restricted area",
size = "large"
) %>% f7Align("center")
),
f7Tab(
tabName = "Restricted 2",
# main content
f7BlockTitle(
title = "2nd restricted area",
size = "large"
) %>% f7Align("center")
)
),
f7Login(id = "loginPage", title = "Welcome", startOpen = FALSE),
f7Login(id = "loginPage2", title = "Welcome", startOpen = FALSE)
)
),
server = function(input, output, session) {
trigger1 <- reactive({
req(input$tabs == "Restricted")
})
trigger2 <- reactive({
req(input$tabs == "Restricted 2")
})
# do not run first since the login page is not yet visible
callModule(
f7LoginServer,
id = "loginPage",
ignoreInit = TRUE,
trigger = trigger1
)
callModule(
f7LoginServer,
id = "loginPage2",
ignoreInit = TRUE,
trigger = trigger2
)
}
)
}
Run the code above in your browser using DataLab