对于R Shiny应用程序,我试图带有基于HTML模板的UI的Intro/Login页面。我能够实现这个链接https://shiny.rstudio.com/articles/templates.html建议。现在,我希望当用户获得登录使用用户名&密码通过介绍页面然后他们被导航到ShinyDashboard。基本上,Intro/Login Page应该有一个HTML模板主题,应用的其他部分有一个ShinyDashboard主题。你能否提供一些能帮助我达到同样目的的提示或例子?R Shiny HTML集成
编辑: 这里的一段代码,我已经写了:
UI
shinyUI(bootstrapPage(
tagList(
tags$head(
tags$link(rel="stylesheet", type="text/css",href="style.css")
)
),
htmlTemplate("htmlpage.html",
uilogin = uiOutput("uiLogin"),
textpass = textOutput("pass")
),
obs = div(class = "span4", uiOutput("obs")),
distplot = div(class = "span8", plotOutput("distPlot"))
))
服务器
Logged = FALSE;
PASSWORD <- data.frame(Brukernavn = c("Windows","Ubuntu"), Passord = c("25d55ad283aa400af464c76d713c07ad","81b073de9370ea873f548e31b8adc081"))
shinyServer(function(input, output) {
source("www/Login.R", local = TRUE)
observe({
if (USER$Logged == TRUE) {
output$obs <- renderUI({
sliderInput("obs", "Number of observations:",
min = 10000, max = 90000,
value = 50000, step = 10000)
})
output$distPlot <- renderPlot({
dist <- NULL
dist <- rnorm(input$obs)
hist(dist, breaks = 100, main = paste("Your password:", input$passwd))
})
}
})
})
登录部分
USER <- reactiveValues(Logged = FALSE)
passwdInput <- function(inputId, label) {
tagList(
tags$label(label),
tags$input(id = inputId, type="password", value="")
)
}
output$uiLogin <- renderUI({
if (USER$Logged == FALSE) {
wellPanel(
textInput("userName", "User Name:"),
passwdInput("passwd", "Pass word:"),
br(),
actionButton("Login", "Log in")
)
}
})
output$pass <- renderText({
if (USER$Logged == FALSE) {
if (!is.null(input$Login)) {
if (input$Login > 0) {
Username <- isolate(input$userName)
Password <- isolate(input$passwd)
Id.username <- which(PASSWORD$Brukernavn == Username)
Id.password <- which(PASSWORD$Passord == Password)
if (length(Id.username) > 0 & length(Id.password) > 0) {
if (Id.username == Id.password) {
USER$Logged <- TRUE
}
} else {
"User name or password failed!"
}
}
}
}
})
output$uiTest <- renderUI({
dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
# TextImput for Username and Password
textInput("username", label = h4("Username"), value = "Enter Username..."),
textInput("password", label = h4("Password"), value = "Enter Password..."),
# Log in Button
actionButton("action", label = "Log in")
)
)
})
此外,还有HTML文件htmlpage.html这是一个介绍页面。现在,使用上面的代码一切工作正常。现在,当用户通过Into页面登录(HTML页面闪亮)时,需要在shinydashboard用户界面中打开图表(obs,displot)。目前,displot正在HTML主题UI中显示。
有没有一种方法可以在ShinyDashboard主题的HTML主题和应用程序的其他部分中有我的介绍(登录页面)。
能否请你让我知道downvote为理由我的问题似乎很清楚,因为我正在寻找在我的多个主题R Shiny App。 – string
我没有downvote,但你应该更专注于一个特定问题的狭义问题,显示你的代码等。 –
@ Hack-R谢谢哈克。我写了一段代码,并试图更详细地解释这个问题。 – string