2016-12-14 8 views
1

私のアプリでは、ユーザーがフォルダを選択し、そのフォルダからファイルを選択する必要があります。光沢のある条件付きパネル

私はconditionalPanel()を使用すると考えました。そのため、ユーザーはフォルダを選択するまで最初のボタンのみを表示します。私はこのコードを書いたが、私はこのエラーメッセージを受け取る、 'オブジェクト'の入力 'が見つかりません'、これを行う正しい方法は何ですか?条件付きパネルを絶対パネルに置くことは問題ですか?

library(shiny) 
library(ggplot2) 

ui <- shinyUI(fluidPage(
    titlePanel(""), 
    fluidRow(
    # select input for selecting a folder 
    column(2, absolutePanel(fixed = TRUE, width = '180px', 
         selectInput("pick_folder", label = '', selected='choose_a_folder', 
           choices = setNames(as.list(c('choose_a_folder', basename(setdiff(list.dirs(recursive = FALSE),'.')))), 
               c('choose_a_folder', basename(setdiff(list.dirs(recursive = FALSE),'.'))))))), 
    # select input for selecting a file absolutePanel then conditionalPanel 
    column(2, absolutePanel(fixed = TRUE, width = '180px', 
         conditionalPanel(condition="input.pick_folder==choose_a_folder", 
           selectInput('pick_file', label = '', selected = 'choose_a_file', 
              choices = setNames(as.list(c('choose_a_file', basename(setdiff(list.files(path=input$pick_folder ,recursive = FALSE),'.')))), 
                   c('choose a file', basename(setdiff(list.files(path=input$pick_folder ,recursive = FALSE),'.')))))))), 
), 
    fluidRow(
    #plot 
    plotOutput('my_plot') 

    ))) 

    # server 
    server <- shinyServer(function(input, output) { 
    output$my_plot <- renderPlot({ 
     dat <- read.table(file=paste(input$pick_folder, input$pick_file, sep='/')) 
     # some plots over dat 
    }) 

    }) 
    shinyApp(ui, server) 

答えて

1

probemは動的にアプリのui一部内のファイルを選択するための選択肢を作成しようとしているから生じます。あなたがこれを行うべき方法ui(あなたのファイル選択)の動的部分を作成することで、あなたのserver一部でuiOutputを使用してrenderUI

次のコードは、あなたが欲しい記述何をやっているようだ:

library(shiny) 
library(ggplot2) 

ui <- shinyUI(fluidPage(
    titlePanel(""), 
    fluidRow(
    # select input for selecting a folder 
    column(2, absolutePanel(fixed = TRUE, width = '180px', 
          selectInput("pick_folder", label = '', selected='choose_a_folder', 
             choices = setNames(as.list(c('choose_a_folder', basename(setdiff(list.dirs(recursive = FALSE),'.')))), 
                  c('choose_a_folder', basename(setdiff(list.dirs(recursive = FALSE),'.'))))))), 
    # select input for selecting a file absolutePanel then conditionalPanel 
    column(2, absolutePanel(fixed = TRUE, width = '180px', 
          conditionalPanel(condition="input.pick_folder==choose_a_folder", 
              # Insert a dynamic bit of UI 
              uiOutput("fileselection") 
              ) 
          ) 
      ) 
), 
    fluidRow(
    #plot 
    plotOutput('my_plot') 

))) 

# server 
server <- shinyServer(function(input, output) { 
    output$my_plot <- renderPlot({ 
    dat <- read.table(file=paste(input$pick_folder, input$pick_file, sep='/')) 
    # some plots over dat 
    }) 

    output$fileselection <- renderUI({ #Define the dynamic UI 
    selectInput('pick_file', label = '', selected = 'choose_a_file', 
       choices = setNames(as.list(c('choose_a_file', basename(setdiff(list.files(path=input$pick_folder ,recursive = FALSE),'.')))), 
            c('choose a file', basename(setdiff(list.files(path=input$pick_folder ,recursive = FALSE),'.')) 
            ) 
       ) 
    ) 
    }) 

}) 

shinyApp(ui, server) 
+0

ありがとうございました!これは私のコードの大部分をサーバに移動しようとする必要があるようですが、これが私の質問に対する解決策であったのは過去2週間です。 –

+1

サーバーはすべての思考が起こる場所です。あなたのコードが何らかの考え方をしているなら、それはおそらくサーバー内にあるはずです。 UIはすべて外観に関するものです(非常に浅い、ugh!)。 –

関連する問題