简体   繁体   中英

Change Text and Colors in Shinymanager Login Page

Im trying to change the text in the login page of shinymanager in R with html code in my script, but it doesn't work. For example I want to change the username by "usuario" and the colors of the frame. Does anyone knows how to do it? Thanks, here is my code.

library(shiny)
library(ggplot2)
library(shinydashboard)
library(DT)
library(dplyr)
library(shinyWidgets)
library(data.table)
library(png) 
library(shinyjs)
library(shinythemes)
library(shinycssloaders)
library(sodium)
library(lubridate)
library(glue)
library(shinymanager)

## estructura shiny ##

inactivity <- "function idleTimer() {
var t = setTimeout(logout, 120000);
window.onmousemove = resetTimer; // catches mouse movements
window.onmousedown = resetTimer; // catches mouse movements
window.onclick = resetTimer;     // catches mouse clicks
window.onscroll = resetTimer;    // catches scrolling
window.onkeypress = resetTimer;  //catches keyboard actions

function logout() {
window.close();  //close the window
}

function resetTimer() {
clearTimeout(t);
t = setTimeout(logout, 120000);  // time is in milliseconds (1000 is 1 second)
}
}
idleTimer();"

ui <- secure_app(

    head_auth = tags$script(inactivity),...
    (normal ui code), 
    )

server <- function(input, output, session) {

    result_auth <- secure_server(check_credentials = check_credentials(credentials)),...
    (normal server code),
    }

shinyApp(ui = ui, server = server)

Hi Nico

You can change theme used by {shinymanager} with argument theme in secure_app , you can use {shinythemes} or create a customized one with {fresh} .

Changing labels is not a currently exported feature yet, but you can do :

lang <- shinymanager:::language$new()
lang$add(
  "Please authenticate" = "Por favor autenticar",
  "Username:" = "Usuario:",
  "Password:" = "Contraseña:",
  "Login" = "Iniciar sesión"
)

The complete list of labels is available here : https://github.com/datastorm-open/shinymanager/blob/master/R/language.R#L44

If you translate all labels, we'll gladly accept a PR to make it available through the package (you can also open an issue if you prefer)

A complete example :

library(shiny)
library(shinymanager)

# UI
ui <- secure_app(
  # Choose a new theme
  theme = shinythemes::shinytheme("flatly"),

  ### EDIT: Add an image ### 
  tag_img = tags$img(
    src = "https://www.r-project.org/logo/Rlogo.png", width = 100
  ),

  # Classic UI
  fluidPage(
    tags$h1("My app")
  )
)


# Credentials to connect to application
credentials <- data.frame(
  user = c("shiny"),
  password = c("shiny"),
  stringsAsFactors = FALSE
)


# Change language
lang <- shinymanager:::language$new()
lang$add(
  "Please authenticate" = "Por favor autenticar",
  "Username:" = "Usuario:",
  "Password:" = "Contraseña:",
  "Login" = "Iniciar sesión"
)


# SERVER
server <- function(input, output, session) {

  result_auth <- secure_server(
    check_credentials = check_credentials(credentials)
  )

}

shinyApp(ui = ui, server = server)

Which gives :

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM