3

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)

Nico
  • 33
  • 4

1 Answers1

6

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 :

enter image description here

Victorp
  • 13,636
  • 2
  • 51
  • 55
  • Thank you very much ! That works perfect for my app... You know if one could insert images or titles in the loggin page? Im kind of new using shiny and shinymanager, so any help is welcome ! Thanks again. – Nico Jan 08 '20 at 14:29
  • Yes you can add image using `tag_img` argument, I edited my answer. – Victorp Jan 10 '20 at 09:04
  • Thanks ! That was exactly the thing I was looking for. You know a good source to learn shiny, but in a developer sense? I mean with this using codes in html or javascript? Thanks again for the help. – Nico Jan 10 '20 at 14:34
  • 3
    When trying to change the language, I get the error: `Error in ..stacktraceon..({ : attempt to apply non-function` – Rafs Mar 22 '21 at 08:44
  • 3
    @Jabro labels can now be set using the `set_labels` function, rather than the example given here. – DJC May 26 '21 at 21:01
  • How to add custom icon to the login page? – Masoud Feb 12 '22 at 06:01