我试图用脚本中的 html 代码更改 R 中 shinymanager 登录页面中的文本,但它不起作用。例如,我想通过“usuario”更改用户名和框架的颜色。有谁知道该怎么做?谢谢,这是我的代码。
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)
最佳答案
嗨尼科
你可以在secure_app
中通过参数theme改变{shinymanager}使用的主题,你可以使用{shinythemes}或使用 {fresh} 创建自定义的.
更改标签不是当前导出的功能,但您可以这样做:
lang <- shinymanager:::language$new()
lang$add(
"Please authenticate" = "Por favor autenticar",
"Username:" = "Usuario:",
"Password:" = "Contraseña:",
"Login" = "Iniciar sesión"
)
完整的标签列表可在此处获得:https://github.com/datastorm-open/shinymanager/blob/master/R/language.R#L44
如果您翻译所有标签,我们很乐意接受 PR 以通过软件包提供它(如果您愿意,也可以打开一个问题)
一个完整的例子:
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)
给出:
关于shiny - 在 Shinymanager 登录页面中更改文本和颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59628481/