2016-03-10 29 views
0

我构建了一个闪亮的应用程序,告诉您剩余多少天,直到您的生日。但在视觉上,我想文本是在一排,而它是目前这样的: enter image description here更改闪亮应用程序的布局

我想这应该很容易,但我是新的闪亮,并没有真正得到它。 这是我的代码: 库(闪亮)

ui <- (shinyUI(fluidPage(
    sidebarPanel(
    strong("Wann wurdest du geboren?"), 
    selectInput("a1",label="Tag", choices=(c(1:31))), 
    selectInput("a2",label="Monat", choices=(c(1:12))), 
    selectInput("a3",label="Jahr", choices=(c(1940:year(Sys.time())))), 

    mainPanel(
     verbatimTextOutput('a_out'), 

     # UI output 
     uiOutput("b1") 
) 
)))) 

server <- shinyServer(function(input, output) { 
    data <- reactive({ 
    Geburtsdatum <- paste0(input$a1,".", input$a2, ".", input$a3) 
    Uhrzeit <- "00:00:01" 
    Geb <- paste(Geburtsdatum, Uhrzeit) 
    geburt <- strptime(c(Geb), format = "%d.%m.%Y %H:%M:%S", tz = "CET") 
    geburtstag <- geburt 
    year(geburtstag) <- year(Sys.time()) 
    gebu <- geburtstag - Sys.time() 
    if(gebu < 0){year(geburtstag) <- year(Sys.time())+1} 
    gebu <- geburtstag - Sys.time() 
    Alter <- ceiling((Sys.time() - geburt)/365) 
    runden <- function(Wert){ 
    trunc(Wert) 
    } 
    decimalpl <- function(Wert){ 
    Wert-trunc(Wert) 
    } 
    list(a = (trunc(gebu)), 
     b = (runden(decimalpl(gebu)*24)), 
     c = (runden(decimalpl(decimalpl(gebu)*24)*60)), 
     d = (runden(decimalpl(decimalpl(decimalpl(gebu)*24)*60)*60)), 
     e = (paste(Alter,".", sep=""))) 
    }) 
    output$b1 <- renderUI({ 
    strong(paste("Noch", data()$a, "Tage,", 
       data()$b, "Stunden,", 
       data()$c, "Minuten, und", 
       data()$d, "Sekunden bis zu deinem", 
       data()$e, "Geburtstag!")) 
    }) 
    }) 


shinyApp(ui = ui, server = server) 

真的谢谢了! 上限:我可以赞美backgorund和文本吗?或者包含一张图片?

+0

错误的括号;而不是selectInput(“a3”,label =“Jahr”,choices =(c(1940:year(Sys.time())))),mainPanel(verbatimTextOutput('a_out'),uiOutput(“b1”))尝试使用selectInput(“a3”,label =“Jahr”,choices =(c(1940:year(Sys.time()))))),mainPanel(verbatimTextOutput('a_out'),uiOutput(“b1”)) – MLavoie

+0

非常感谢! –

回答

1

至于你的应用程序的样式,这里是一个例子,给出了如何给你的文本,背景和添加图像上色的提示。

我希望这会有所帮助。

library(shiny) 

ui <- shinyUI(
    fluidPage(
    sidebarPanel(style = "background-color: orange;", 
     strong("Wann wurdest du geboren?"), 
     selectInput("a1",label="Tag", choices=(c(1:31))), 
     selectInput("a2",label="Monat", choices=(c(1:12))), 
     selectInput("a3",label="Jahr", choices=(c(1940:year(Sys.time())))) 
    ), 
    mainPanel(
     #verbatimTextOutput('a_out'), 
     tags$img(src = "http://media.kuechengoetter.de/media/735/13553229675100/geburtstag-kuechengoetter.jpg", style = "z-index: -1; position: fixed;"), 
     # UI output 
     uiOutput("b1", style = "color: blue;") 
    ) 
)) 

server <- shinyServer(function(input, output) { 
    data <- reactive({ 
    Geburtsdatum <- paste0(input$a1,".", input$a2, ".", input$a3) 
    Uhrzeit <- "00:00:01" 
    Geb <- paste(Geburtsdatum, Uhrzeit) 
    geburt <- strptime(c(Geb), format = "%d.%m.%Y %H:%M:%S", tz = "CET") 
    geburtstag <- geburt 
    year(geburtstag) <- year(Sys.time()) 
    gebu <- geburtstag - Sys.time() 
    if(gebu < 0){year(geburtstag) <- year(Sys.time())+1} 
    gebu <- geburtstag - Sys.time() 
    Alter <- ceiling((Sys.time() - geburt)/365) 
    runden <- function(Wert){ 
     trunc(Wert) 
    } 
    decimalpl <- function(Wert){ 
     Wert-trunc(Wert) 
    } 
    list(a = (trunc(gebu)), 
     b = (runden(decimalpl(gebu)*24)), 
     c = (runden(decimalpl(decimalpl(gebu)*24)*60)), 
     d = (runden(decimalpl(decimalpl(decimalpl(gebu)*24)*60)*60)), 
     e = (paste(Alter,".", sep=""))) 
    }) 
    output$b1 <- renderUI({ 
    strong(paste("Noch", data()$a, "Tage,", 
       data()$b, "Stunden,", 
       data()$c, "Minuten, und", 
       data()$d, "Sekunden bis zu deinem", 
       data()$e, "Geburtstag!")) 
    }) 
}) 


shinyApp(ui = ui, server = server) 
+0

这太好了!非常感谢! –

相关问题