2016-12-14 5 views
-3

R Shiny Appの場合、HTMLテンプレートに基づいたUIを持つIntro/Loginページが必要です。私はこのリンクで提案されているようにこれを達成することができます。ユーザーがにログインしたときにというユーザー名を使用してユーザー名&からパスワードにアクセスすると、ShinyDashboardにナビゲートされます。基本的には、イントロ/ログインページには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ページ)、図表(obs、displot)をshinydashboardユーザーインターフェイスで開いたときに必要です。現在、 displotがHTMLテーマUIに表示されています。

ShinyDashboardテーマのHTMLテーマやアプリの他の部分でIntro(ログインページ)を使用できる方法はありますか?

+0

あなたは私のようにdownvoteの理由を聞かせてもらえを含めます私の質問は、私が複数のテーマを私のRシャイニーアプリ。 – string

+1

私はdownvoteをしませんでしたが、特定の問題に焦点を絞り、コードなどを表示してください。 –

+0

@ Hack-R Thanks Hack。私は自分のコードを書いて、その問題をより詳細に説明しようとしました。 – string

答えて

0

renderUI、renderMenu、uioutput機能を使用して達成できます。ここでは、質問されたクエリを達成するためのコードの一部です。

UI

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ページの

は、bodyタグ内{{uilogin}}