2017-12-08 8 views
1

Shinyアプリケーションでフォルダへのパスを指定できるようにするには(ローカル)、の表示を選択します。次のコードは動作しますが、フォルダが選択されるまでverbatimTextOutputで "character(0)"を非表示にする方法はわかりません。条件付きパネル(私のコードでコメントアウトされています)を試しましたが、ここで条件として何を使用するのかわかりません(shinyDirButtonは標準的なアクションボタンではないので...)。ありがとうございました!Shinyで選択したフォルダパスを表示する

library(shiny) 
library(shinyFiles) 

# Define UI for application that draws a histogram 
ui <- fluidPage(

    # Application title 
    mainPanel(
    shinyDirButton("dir", "Input directory", "Upload"), 
    #conditionalPanel(
     #condition = "???", 
     verbatimTextOutput('dir') 
    #) 
) 
) 

server <- function(input, output) { 

    shinyDirChoose(input, 'dir', roots = c(home = '~'), filetypes = c('', 'txt','bigWig',"tsv","csv","bw")) 

    dir <- reactive(input$dir) 
    output$dir <- renderPrint({parseDirPath(c(home = '~'), dir())}) 

    observeEvent(
    ignoreNULL = TRUE, 
    eventExpr = { 
     input$dir 
    }, 
    handlerExpr = { 
     home <- normalizePath("~") 
     datapath <<- file.path(home, paste(unlist(dir()$path[-1]), collapse = .Platform$file.sep)) 
    } 
) 
} 

# Run the application 
shinyApp(ui = ui, server = server) 

私は見つけることができた最も近いの質問はこれですが、それは私の問題を解決していません:サーバー機能でR conditionalPanel reacts to output

答えて

1

を、代わりにrenderPrintrenderTextを使用します。

library(shiny) 
library(shinyFiles) 

# Define UI for application that draws a histogram 
ui <- fluidPage(# Application title 
    mainPanel(
    shinyDirButton("dir", "Input directory", "Upload"), 
    verbatimTextOutput("dir", placeholder = TRUE) # added a placeholder 
)) 

server <- function(input, output) { 
    shinyDirChoose(
    input, 
    'dir', 
    roots = c(home = '~'), 
    filetypes = c('', 'txt', 'bigWig', "tsv", "csv", "bw") 
) 

    dir <- reactive(input$dir) 
    output$dir <- renderText({ # use renderText instead of renderPrint 
    parseDirPath(c(home = '~'), dir()) 
    }) 

    observeEvent(ignoreNULL = TRUE, 
       eventExpr = { 
       input$dir 
       }, 
       handlerExpr = { 
       home <- normalizePath("~") 
       datapath <<- 
        file.path(home, paste(unlist(dir()$path[-1]), collapse = .Platform$file.sep)) 
       }) 
} 

# Run the application 
shinyApp(ui = ui, server = server) 
+0

ありがとうございました、 出来た!しかし、条件付き書式設定を使用し、選択後にのみフィールド全体を表示させることは可能だと思いますか? – kintany

+0

これに条件付きの書式設定は必要ありません。 'verbatimTextOutput'関数で' placeholder = FALSE'を設定するだけです。 – jsb

+0

私は新しい質問をしますが、おそらくここで簡単な答えがあります。 verbatimTextOutputではプレースホルダを持たないが、ユーザがフォルダを選択する前に静的にする方法を知っていますか?たとえば、現在のディレクトリへのパスです。大いに感謝する。 – kintany

関連する問題