2015-11-16 66 views
4

我想在我的shinyApp中使用shinyFiles庫,以便爲用戶提供選擇一組文件或目錄的可能性。 我的想法是使用根據複選框選擇而改變的uiOutput。shinyfiles和renderUI不能正常工作

在這裏,我報告的代碼,也許是比文字更explicative

UtilityUI <- fluidPage(
    titlePanel("page1"), 
    fluidRow(
    column(2, 
     wellPanel(
       tags$p("Check the box below if you want to choose an entire directory"), 
       checkboxInput(inputId = 'directory_flag', label = 'Directory path?', value = FALSE), 
       uiOutput("input_selection_ui") 
      ) 
    ), 
    column(8 
      #... 
      ) 
) 
) 

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

    output$input_selection_ui <- renderUI({ 
    if(input$directory_flag == TRUE) { 
     shinyDirButton(id = "infiles", label = "Choose directory", title = "Choose a directory") 
    } else { 
     shinyFilesButton(id = "infiles", label = "Choose file(s)", title = "Choose one or more files", multiple = TRUE) 
    } 
    }) 


    shinyFileChoose(input, 'infiles', roots=getVolumes(), session=session, restrictions=system.file(package='base')) 
    shinyDirChoose(input, 'infiles', roots=getVolumes(), session=session, restrictions=system.file(package='base')) 
} 

shinyApp(UtilityUI, UtilityServer) 

按下「shinyFiles」按鈕,當問題新生兒:彈出窗口不加載根,在這兩種情況下( shinyDirButton和shinyFilesButton)。

如果我不使用uiOutput功能一切正常。但在這種情況下,我不能改變我的UI dinamically ...

非常感謝您的答覆,

Inzirio

回答

1

看來我無法與renderUI()一起工作。相反,我使用conditionalPanel()實現了相同的行爲來顯示替代按鈕。這似乎工作。以下是代碼:

ui <- shinyUI(fluidPage(
    checkboxInput(
    inputId = 'directory_flag', 
    label = 'Directory path?', 
    value = FALSE 
), 

    conditionalPanel(
    "input.directory_flag == 0", 
    shinyFilesButton(
     id = "infile", 
     label = "Choose file(s)", 
     title = "Choose one or more files", 
     multiple = TRUE 
    ) 
), 
    conditionalPanel(
    "input.directory_flag == 1", 
    shinyDirButton(id = "indir", label = "Choose directory", title = "Choose a directory") 
) 
)) 

server <- shinyServer(function(input, output, session) { 
    shinyFileChoose(
    input, 
    'infile', 
    roots = getVolumes(), 
    session = session, 
    restrictions = system.file(package = 'base') 
) 
    shinyDirChoose(
    input, 
    'indir', 
    roots = getVolumes(), 
    session = session, 
    restrictions = system.file(package = 'base') 
) 
}) 

shinyApp(ui, server) 
+0

此實施如果已部署,則只允許訪問服務器文件系統。我想知道是否有辦法啓用訪問客戶端文件系統? – Sasha

+0

@inzirio沒有解決方案?謝謝 – DemetriusRPaula

+0

@ddiez沒有解決方案?謝謝 – DemetriusRPaula