Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shiny 隐藏在服务器中使用模块创建的按钮_Shiny_Shinyjs - Fatal编程技术网

Shiny 隐藏在服务器中使用模块创建的按钮

Shiny 隐藏在服务器中使用模块创建的按钮,shiny,shinyjs,Shiny,Shinyjs,我有一个应用程序,它有很多tabItems,对于每一个,我都指定哪些文件应该放在某个目录中(在下面的示例中,我使用getwd()),以便该应用程序可以运行某些过程 这些文件将与按钮和其他功能一起列在“表”中 有时,在一个选项卡项中生成的文件将用作另一个选项卡项中的输入。。 我想将模块中为该文件动态创建的按钮隐藏在选项卡item中,该选项卡使用该文件作为输入 我已经找到了如何做到这一点,但我想知道是否有可能从服务器上做到这一点 以下是我试用过的应用程序的小版本: ## global ---- li

我有一个应用程序,它有很多
tabItem
s,对于每一个,我都指定哪些文件应该放在某个目录中(在下面的示例中,我使用getwd()),以便该应用程序可以运行某些过程

这些文件将与按钮和其他功能一起列在“表”中

有时,在一个
选项卡项中生成的文件将用作另一个选项卡项中的输入。。
我想将模块中为该文件动态创建的按钮隐藏在
选项卡item
中,该选项卡使用该文件作为输入

我已经找到了如何做到这一点,但我想知道是否有可能从服务器上做到这一点

以下是我试用过的应用程序的小版本:

## global ----
library(shiny)
library(shinydashboard)
library(shinyBS)
library(shinyjs)

find_file_flex <- function(dir, extension, name_pattern, temp.rm=FALSE) {
  files <- list.files(dir, pattern = name_pattern)
  exts <- stringr::str_sub(files, -nchar(extension))
  files <- files[exts == extension]
  if(temp.rm) {
    temp <- stringr::str_detect(files, pattern = "^([~][$])")
    files <- files[!temp]
  }

  if (length(files) == 1){
    file.path(dir, files)
  } else if (length(files) > 1) {
    date <- gsub(pattern = "-", replacement = "", basename(dir))
    time_start <- unlist(gregexpr(pattern = date, files))
    times <- stringr::str_sub(files, time_start, time_start + 13)
    file.path(dir, files[times == max(times)])
  } else { NA }
}

## dir_files ----
dir_files <- list(
  file1 = list(
    name_pattern = "-name_pattern1",
    extension = ".txt",
    sep = ";",
    dec = ".",
    label = "File1"
  ),
  file2 = list(
    name_pattern = "-name_pattern2",
    extension = ".txt",
    sep = ";",
    dec = ".",
    label = "File2"
  )
)

## files_ui ----
files_ui <- tagList(
  file1 = list(
    button_icon = icon("download"),
    info_modal_content = div("1. Much info! Such knowledge!")
  ),
  file2 = list(
    button_icon = icon("refresh"),
    info_modal_content = div("2. Much info! Such knowledge!")
  )
)

## chores_info ----
chores_info <- list(
  home = list(
    label = "Homez!",
    input = c("file1","file2"),
    output = "file2"
  )
)

## modules ----
tr_fileOutput <- function(id) {
  ns <- NS(id)
  tagList(
    tagList(
      tags$tr(
        # id = ns("tr"),
        tags$td(uiOutput(ns("info_actionLink")), colspan = "1"),
        tags$td(uiOutput(ns("labelLink")), colspan = "7"),
        tags$td(uiOutput(ns("button")), colspan = "1")
      ),
      tags$tr(
        tags$td(uiOutput(ns("warn")), colspan = "10")
      )      
    ),
    uiOutput(ns("info_modal"))
  )
}
tr_file <- function(input, output, session, file, path) {
  ns <- session$ns

  file_path <- reactive({
    invalidateLater(2000, session)

    obj <- dir_files[[file]]
    if(is.null(obj$dir)) obj$dir <- path()
    find_file_flex(obj$dir, obj$extension, obj$name_pattern, temp.rm = TRUE)
  })

  output$info_actionLink <- renderUI({
    actionLink(ns("info_actionLink"), label = NULL, icon = icon("info-circle"))
  })
  output$labelLink <- renderUI({
    label <- dir_files[[file]]$label
    if(is.na(file_path())) return(label)
    actionLink(ns("labelLink"), label = label)
  })
  output$button <- renderUI({
    icon <- files_ui[[file]]$button_icon
    if(is.null(icon)) return(NULL)
    bsButton(ns("button"), label = NULL, icon = icon,
             size = "extra-small", class = "bvmf-blue")
  })
  output$info_modal <- renderUI({
    content <- files_ui[[file]]$info_modal_content

    title <- dir_files[[file]]$name_pattern
    title <- div("Give me the Info ", tags$small(span("(", title, ")")))

    bsModal(ns("info_modal"), title = title, trigger = NULL, content)
  })

  # trigger info_modal
  observeEvent(input[["info_actionLink"]], 
               toggleModal(session, "info_modal", toggle = "open"))
  # hyperlink para o labelLink
  observeEvent(input[["labelLink"]], shell.exec(file_path()))
}
table_filesOutput <- function(id) {
  ns <- NS(id)
  tagList(
    uiOutput(ns("info_modal")),
    htmlOutput(ns("table"))
  )
}
table_files <- function(input, output, session, files, path) {
  ns <- session$ns

  observe({
    lapply(files, function(file) {
      callModule(module = tr_file, id = file,
                 file = file, path = path)
    })
  })

  output$table <- renderUI({
    x <- lapply(files, function(file) tr_fileOutput(ns(file))[1] )
    tags$table(x, id = ns("table"), style = "width: 100%;")
  })
  output$info_modal <- renderUI({
    lapply(files, function(file) tr_fileOutput(ns(file))[2] )
  })
}

## ui ----
ui <- dashboardPage(
  skin = "blue",

  dashboardHeader(
    title = format(Sys.Date(), "%d/%m/%Y")
  ),
  dashboardSidebar(
    sidebarMenu(
      id = "sidebarMenu",
      menuItem("Home", tabName = "home", icon = icon("home"))
    )
  ),

  dashboardBody(
    id = "dashboardBody",
    useShinyjs(),
    tabItems(
      tabItem(
        tabName = "home",
        column(
          width = 3,
          wellPanel(
            table_filesOutput("home-input")
          ),
          wellPanel(
            table_filesOutput("home-output")
          )
        )
      )
    )
  )
)

## server ----
server <- shinyServer(function(input, output, session) {
  date <- reactive({ Sys.Date() })
  dir_date <- reactive({ getwd() })

  callModule(table_files, "home-input",
             files = chores_info[["home"]]$input, path = dir_date)
  callModule(table_files, "home-output",
             files = chores_info[["home"]]$output, path = dir_date)
  observe({
    # not sure why this is not hiding the button :(
    hide("home-input-file2-button")
  })

  # code to deal with buttons and such
  session$onSessionEnded(stopApp)
})

##   ----
shinyApp(ui = ui, server = server)
##全球----
图书馆(闪亮)
图书馆(shinydashboard)
图书馆(shinyBS)
图书馆(shinyjs)
查找\u文件\u flex