2017-05-22 4 views
4

나는 Shiny의 showNotification 기능을 사용자 정의하려고합니다. 오른쪽 아래에 반대R Shiny showNotification

https://gallery.shinyapps.io/116-notifications/

라는 메시지를 원하는 화면의 중앙에 생성합니다. 나는 이것이 기본적으로 설정 될 수 있다고 생각하지 않지만 누군가가 이것을 성취 할 수있는 방법을 제안하기를 희망합니다.

감사합니다.

답변

6

CSS 스타일 속성을 덮어 쓰려면 $ style 태그를 사용할 수 있습니다. 또한 이러한 접근 방식으로 너비와 높이와 같은 다른 속성을 조정할 수 있습니다. 아래 제공된 앱 템플릿은 내가 제공 한 링크의 코드에서 가져 왔습니다. 알리미를위한이 특정 CSS 사용자 정의는 또 다른 기존 답변에서 사용되었지만 지금 참조 할 링크를 찾지 못했습니다.

shinyApp(
    ui = fluidPage(
    tags$head(
     tags$style(
     HTML(".shiny-notification { 
      position:fixed; 
      top: calc(50%);; 
      left: calc(50%);; 
      } 
      " 
      ) 
     ) 
    ), 
    textInput("txt", "Content", "Text of message"), 
    radioButtons("duration", "Seconds before fading out", 
       choices = c("2", "5", "10", "Never"), 
       inline = TRUE 
    ), 
    radioButtons("type", "Type", 
       choices = c("default", "message", "warning", "error"), 
       inline = TRUE 
    ), 
    checkboxInput("close", "Close button?", TRUE), 
    actionButton("show", "Show"), 
    actionButton("remove", "Remove most recent") 
), 
    server = function(input, output) { 
    id <- NULL 

    observeEvent(input$show, { 
     if (input$duration == "Never") 
     duration <- NA 
     else 
     duration <- as.numeric(input$duration) 

     type <- input$type 
     if (is.null(type)) type <- NULL 

     id <<- showNotification(
     input$txt, 
     duration = duration, 
     closeButton = input$close, 
     type = type 
    ) 
    }) 

    observeEvent(input$remove, { 
     removeNotification(id) 
    }) 
    } 
) 
+0

완벽한 Mr BigDataScientist! –