小编Rob*_*rto的帖子

R/Shiny:从服务器上的文件夹下载多个文件(zip)

我想创建一个 zip 存档(包含多个 xlsx 文件)并将其保存在本地。文件存储在服务器端的文件夹中。用户使用 checkboxInput 选择要压缩的文件。

这是复选框的代码:

  get.files <- reactive({
    list.files("output_file/")
  })  

obsList <- list()

output$links_list <- renderUI({    
    lapply(as.list(1:length(get.files())), function(i)
    {
      btName <- get.files()[i]
      # creates an observer only if it doesn't already exists
      if (is.null(obsList[[btName]])) {
         obsList[[btName]] <<- btName 
      }
      fluidRow(checkboxInput(btName, get.files()[i])  )
    })
})
Run Code Online (Sandbox Code Playgroud)

复选框是动态创建的,读取文件夹(“output_file/”)中的内容。每个复选框附近都有文件名。

下载的函数是:

output$downloadzip<-downloadHandler(
    filename = function(){
      paste0("Extract.zip")
    },
    content = function(file){
      files <- NULL;
      for (i in 1:length(obsList)){
        if(input[[obsList[[i]]]])
          files <- c(paste("output_file/",obsList[[i]],sep=""),files)
      }
      #create the zip file
      zip(file,files)
    },
    contentType = "application/zip"
  ) …
Run Code Online (Sandbox Code Playgroud)

unix zip r sh shiny

2
推荐指数
1
解决办法
2659
查看次数

闪亮的可折叠 checkboxGroupInput

我使用 renderUI 和 checkboxGroupInput 创建了一组复选框。结果如下: 在此处输入图片说明

我现在想获得的是这样的:

在此处输入图片说明

只显示最重要的结果,并可以展开复选框列表。

关于如何获得这个的任何建议?

复选框的代码如下:

服务器.R

    my_checkboxGroupInput <- function(variable, label,choices, selected, colors,perc){
    my_names <- choices
    log_funct("my_names",my_names,   verbose=T)
    if(length(names(choices))>0) my_names <- names(choices)
    log_funct("names(my_names)",my_names,   verbose=T)
    log_funct("choices",choices,   verbose=T)
     log_funct("selected",selected,   verbose=T)
    div(id=variable,class="form-group shiny-input-checkboxgroup shiny-input-container shiny-bound-input",
        HTML(paste0('<label class="control-label" for="',variable,'">',label,'</label>')),
        div( class="shiny-options-group",
             HTML(paste0('<div class="checkbox">',
                         '<label style="width: 100%">',
                         '<input type="checkbox" name="', variable, 
                         '" value="', choices, 
                         '"', ifelse(choices %in% selected, 'checked="checked"', ''), 
                         '/>',
                         #'<span ', ifelse(choices %in% selected, paste0('style=" background-color:',colors ,'; display: inline-block; white-space: nowrap; width: ',perc, '%;"'),''), '>',my_names,'</span>',
                         '<span ', paste0('style=" background-color:',colors …
Run Code Online (Sandbox Code Playgroud)

html css checkbox r shiny

1
推荐指数
1
解决办法
645
查看次数

标签 统计

r ×2

shiny ×2

checkbox ×1

css ×1

html ×1

sh ×1

unix ×1

zip ×1