【问题标题】:div in shiny overriding scroll bars for whole app整个应用程序的闪亮覆盖滚动条中的 div
【发布时间】:2019-06-16 19:15:33
【问题描述】:

我正在尝试使用一个包,该包允许用户以闪亮的方式绘制他们的数据 (esquiss)。它工作正常。然而,包装中闪亮模块的用户界面需要一个固定高度的容器。因此,我将模块的调用放在了按钮调用的 tag$div 中(在模态框内)。

问题是这个模块的调用似乎摆脱了应用程序主页的所有滚动条(所以我不能滚动到主页的底部(它是一个单页应用程序)。 如何限制模块的 html 以防止它覆盖应用程序的其余部分?被调用模块的代码是here

我的可重现示例如下:

ui.R

library(shiny)
library(esquisse)
library(shinyBS)

ui <- fluidPage(
  dashboardPage(
    dashboardHeader(title = ''),
    dashboardSidebar(
      sidebarMenu(
        menuItem("Dashboard")
      )),

  dashboardBody(   
      actionButton(inputId = "esquissGraphs",label = "esquissGraphs"),
      DT::dataTableOutput("mytable"),
      bsModal("modalExample", "Data Table", "esquissGraphs", size = "large",

  tags$h1("Use esquisse as a Shiny module"),
  radioButtons(
    inputId = "data",
    label = "Data to use:",
    choices = c("Mydftbbinnit", "mtcars"),
    inline = TRUE
  ),
  tags$div(
    style = "height: 700px;", # needs to be in fixed height container
    esquisserUI(
      id = "esquisse",
      header = FALSE, # dont display gadget title
      choose_data = FALSE # dont display button to change data
    )
  )
    )
)
)
)

server.R

RV <- reactiveValues(data = data.frame())
RV2 <- reactiveValues(data = data.frame())

server <- function(input, output, session) {

n<-c("1","434","101")
t<-c("Bugs","Mugs","Thugs")
RV$data<-data.frame(n,t,stringsAsFactors = FALSE)  

o<-c("1","434","101")
p<-c("Bugs","Mugs","Thugs")
RV2$data<-data.frame(o,p,stringsAsFactors = FALSE)  

output$mytable = DT::renderDataTable({
  mtcars
})


data_r <-reactiveValues(data = data.frame())
observeEvent(input$data, {
    if (input$data == "Mydftbbinnit") {
      data_r$data <- RV$data
      data_r$name <- "Mydftbbinnit"
    } else {
      data_r$data <- RV2$data
      data_r$name <- "The rest"
    }
  })
callModule(module = esquisserServer, id = "esquisse", data = data_r)
}
shinyApp(ui, server)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    你需要添加

    tags$style("html, body {overflow: visible !important;")
    

    在您的 UI 中强制显示滚动条。

    来源:https://github.com/dreamRs/esquisse/blob/master/R/esquisserUI.R

    完整示例:

    library(shiny)
    library(shinydashboard)
    library(esquisse)
    library(shinyBS)
    library(shiny)
    library(esquisse)
    library(shinyBS)
    
    ui <- fluidPage(
      dashboardPage(
        dashboardHeader(title = ""),
        dashboardSidebar(
          sidebarMenu(
            menuItem("Dashboard")
          )
        ),
    
        dashboardBody(
          tags$style("html, body {overflow: visible !important;"),
          actionButton(inputId = "esquissGraphs", label = "esquissGraphs"),
          DT::dataTableOutput("mytable"),
          bsModal("modalExample", "Data Table", "esquissGraphs",
            size = "large",
    
            tags$h1("Use esquisse as a Shiny module"),
            radioButtons(
              inputId = "data",
              label = "Data to use:",
              choices = c("Mydftbbinnit", "mtcars"),
              inline = TRUE
            ),
            tags$div(
              style = "height: 700px;", # needs to be in fixed height container
              esquisserUI(
                id = "esquisse",
                header = FALSE, # dont display gadget title
                choose_data = FALSE # dont display button to change data
              )
            )
          )
        )
      )
    )
    
    RV <- reactiveValues(data = data.frame())
    RV2 <- reactiveValues(data = data.frame())
    
    server <- function(input, output, session) {
      n <- c("1", "434", "101")
      t <- c("Bugs", "Mugs", "Thugs")
      RV$data <- data.frame(n, t, stringsAsFactors = FALSE)
    
      o <- c("1", "434", "101")
      p <- c("Bugs", "Mugs", "Thugs")
      RV2$data <- data.frame(o, p, stringsAsFactors = FALSE)
    
      output$mytable <- DT::renderDataTable({
        mtcars
      })
    
    
      data_r <- reactiveValues(data = data.frame())
      observeEvent(input$data, {
        if (input$data == "Mydftbbinnit") {
          data_r$data <- RV$data
          data_r$name <- "Mydftbbinnit"
        } else {
          data_r$data <- RV2$data
          data_r$name <- "The rest"
        }
      })
      callModule(module = esquisserServer, id = "esquisse", data = data_r)
    }
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 2017-04-07
      • 1970-01-01
      • 2018-05-29
      • 1970-01-01
      • 2019-01-04
      • 2019-02-22
      • 2013-07-08
      • 2013-07-07
      相关资源
      最近更新 更多