如何在miniPage中使用shinyFiles中的shinyDirButton?

时间:2017-07-17 21:51:59

标签: r shiny

请看一下这段代码:

#' @import shiny
#' @import miniUI
#' @export
test <- function(numCols = 3) {
  library(shiny)
  library(shinyFiles)
  library(miniUI)
  volumes <- c('R Installation'=R.home())
  ui <- miniPage(style = "overflow-y:scroll; max-height: 600px",scrollable = TRUE,
                 gadgetTitleBar(span(strong("Granola"))),
                 wellPanel(id = "tPanel",
                           style = "overflow-y:scroll; max-height: 600px",
                             shinyDirButton("dir", "Chose directory", "Upload"),
                             verbatimTextOutput("dir"),
                             uiOutput("fileSelect")
                 )
  )

  server <- function(input, output, session) {
    library(shiny)
  }

  viewer <- shiny::dialogViewer("test", width = 800, height = 700)
  shiny::runGadget(shiny::shinyApp(ui, server), viewer = viewer,
                   stopOnCancel = FALSE)
}
test()

小工具内的弹出窗口不允许用户点击&#34;选择&#34;按钮。

miniui and shinyfolder

你知道如何管理tu允许滚动或移动弹出窗口吗?

问候

1 个答案:

答案 0 :(得分:0)

shinyFiles构建的模式对话框继承自.modal overflow: hidden引导程序类,您可以使用

覆盖它
tags$style( "#dir-modal{ overflow: scroll ; }", type = "text/css" )

你的ui代码中的某处,或者也许:

tags$style( ".sF-modalContainer{ overflow: scroll ; }", type = "text/css" )

否则,您可以创建自己的shinyDirButton修改版本以进行更改。

shinyDirButton <- function(id, ...){
  x <- shinyFiles::shinyDirButton(id, ...)
  x[[1]]$children <- append( 
    x[[1]]$children, 
    list( tags$style(glue("#{id}-modal{{ overflow: scroll; }}")) )  
  )
  x
}

这样您就不必手动跟踪所有shinyDirButton的css类。这是我的完整代码:

library(shiny)
library(shinyFiles)
library(miniUI)
library(glue)

my <- list( shinyDirButton = function(id, ...){
  x <- shinyFiles::shinyDirButton(id, ...)
  x[[1]]$children <- append( 
    x[[1]]$children, 
    list( tags$style(glue("#{id}-modal{{ overflow: scroll; }}")) )  
  )
  x
} )

test <- function(numCols = 3) {

  volumes <- c('R Installation'=R.home())
  ui <- miniPage(
    style = "overflow-y:scroll; max-height: 600px",
    scrollable = TRUE,

    gadgetTitleBar(span(strong("Granola"))),
    wellPanel(id = "tPanel",
      my$shinyDirButton("vfzzfz", "Chose directory", "Upload"),
      verbatimTextOutput("dir"),
      uiOutput("fileSelect")
    )

  )

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

  }

  viewer <- shiny::dialogViewer("test", width = 800, height = 700)
  shiny::runGadget(shiny::shinyApp(ui, server), viewer = viewer,
    stopOnCancel = FALSE)
}

test()