Переместить R Shiny showNotification на определенный div - PullRequest
0 голосов
/ 30 марта 2020

Тесно связанный с этим вопросом , я пытаюсь переместить showNotification ´s к определенному div, который уже находится на странице. Есть ли простой способ сделать это?

Следующее приложение должно проиллюстрировать проблему. Уведомления в правом нижнем углу должны go в желтом div.

library(shiny)

ui=shinyUI(fluidPage(
                  tags$head(
                    tags$style(HTML("
                                    #error {
                                      width: 100%;
                                      border: black 1px solid;
                                      padding: 5px;
                                      margin: 10px 0;
                                      background-color: #f7f2d9;
                                    }
                                    "))
                  ),
                  sidebarLayout(
                    sidebarPanel(
                      sliderInput("lambda","Number",min = 1,max = 100,value = 27)
                    ),
                    mainPanel(
                      h3("Move the slider above 28 to trigger a Notification! "),
                      plotOutput("algebra"),
                      div(id = "error", p("The notifications should appear in here")),
                      tableOutput('table')
                    )
                  )
))

server=function(input, output) {
  output$algebra <- renderPlot({
    if (input$lambda > 28){
      showNotification("How can I put this message in the #error div?", id = "error", type = "warning", duration = NULL)
      return(NULL)
    }
    n <- 1:100
    lambda <- seq(min(n), max(n), length.out = input$lambda)
    plot((2*lambda)+3, type = "o",xlab= "X (number of data points)", ylab = "Y = 2x+3")
  })

  output$table <- renderTable(iris)
}

shinyApp(ui,server)

1 Ответ

1 голос
/ 31 марта 2020

Похоже, что это работает:

library(shiny)
library(shinyjs)

ui=shinyUI(fluidPage(
  useShinyjs(),
  tags$head(
    tags$style(HTML("
                    #error {
                      width: 100%;
                      border: black 1px solid;
                      padding: 5px;
                      margin: 10px 0;
                      background-color: #f7f2d9;
                    }
                    #shiny-notification-panel {
                      position: static;
                    }
                    "))
  ),
  ......

и server:

  output$algebra <- renderPlot({
    if(input$lambda > 28){
      showNotification("How can I put this message in the #error div?", type = "warning", duration = NULL)
      runjs('setTimeout(function(){$("#error").append($("#shiny-notification-panel"))},0);')
      return(NULL)
    }
    ......

Хотя тестирование не проводилось. Альтернатива - bsAlert из пакета shinyBS.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...