【问题标题】:R Shiny HTML IntegrationR闪亮的HTML集成
【发布时间】:2016-12-14 04:26:32
【问题描述】:

对于一个 R Shiny 应用程序,我试图提供一个介绍/登录页面,它的 UI 基于 HTML 模板。我能够按照此链接https://shiny.rstudio.com/articles/templates.html 中的建议实现此目的。现在,我希望当用户通过 Intro Page 使用用户名和密码登录时,他们会被导航到 ShinyDashboard。基本上,介绍/登录页面应该有一个 HTML 模板主题,应用程序的其他部分有一个 ShinyDashboard 主题。您能否提出任何可以帮助我实现相同目标的提示或示例?

编辑: 这是我写的一段代码:

用户界面

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 中显示。

有没有一种方法可以让我的介绍(登录页面)在 HTML 主题中和应用程序的其他部分在 ShinyDashboard 主题中。

【问题讨论】:

  • 能否请您告诉我拒绝投票的原因,因为我的问题似乎很清楚,因为我希望在我的 R Shiny 应用程序中有多个主题。
  • 我没有投反对票,但您应该将您的问题更集中在特定问题上,显示您的代码等。
  • @Hack-R 谢谢哈克。我已经编写了我的一段代码,并试图更详细地解释这个问题。

标签: html r shiny shinydashboard


【解决方案1】:

可以使用renderUI,renderMenu, uioutput函数来实现。下面是实现查询的部分代码。

用户界面

shinyUI(
 dashboardPage(
  dashboardHeader(),
   dashboardSidebar(sidebarMenu(id="sidebartabs",menuItemOutput("side"))),
     dashboardBody(

   uiOutput("page")

  )
)
)

服务器

observe({
if (USER$Logged == FALSE){

output$page <- renderUI({

  # Integration of Custom HTML Page with login page

shinyUI(bootstrapPage(

htmlTemplate("htmlpage.html",

     uilogin = loginpanel()
    )

  ))
})
}
if (USER$Logged == TRUE){    

output$side <- renderMenu({
  inp$sidebarpanel
})

isolate({updateTabItems(session, "sidebartabs")})

output$page <- renderUI({
  inp$main      
})
}})

html页面

在正文标签中包含 {{ uilogin }}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-08
    相关资源
    最近更新 更多