R: Create a connection to the server side filesystem

shinyFiles-observers {shinyFiles} | R Documentation

## Create a connection to the server side filesystem

### Description

These function sets up the required connection to the client in order for the user to navigate the filesystem. For this to work a matching button should be present in the html, either by using one of the button generating functions or adding it manually. See `shinyFiles-buttons()` for more details.

### Usage

    shinyFileChoose(input, id, updateFreq = 0, session = getSession(),
      defaultRoot = NULL, defaultPath = "", ...)

    shinyDirChoose(input, id, updateFreq = 0, session = getSession(),
      defaultPath = "", defaultRoot = NULL, ...)

    shinyFileSave(input, id, updateFreq = 0, session = getSession(),
      defaultPath = "", defaultRoot = NULL, ...)

### Arguments

`input` | The input object of the `shinyServer()` call (usually `input`)
`id` | The same ID as used in the matching call to `shinyFilesButton` or as the id attribute of the button, in case of a manually defined html. This id will also define the id of the file choice in the input variable
`updateFreq` | The time in milliseconds between file system lookups. This determines the responsiveness to changes in the filesystem (e.g. addition of files or drives). For the default value (0) changes in the filesystem are shown only when a shinyFiles button is clicked again
`session` | The session object of the shinyServer call (usually `session`).
`defaultRoot` | The default root to use. For instance if `roots = c('wd' = '.', 'home', '/home')` then `defaultRoot` can be either `'wd'` or `'home'`.
`defaultPath` | The default relative path specified given the `defaultRoot`.
`...` | Arguments to be passed on to `fileGetter()` or `dirGetter()`

### Details

Restrictions on the access rights of the client can be given in several ways. The root parameter specifies the starting position for the filesystem as presented to the client. This means that the client can only navigate in subdirectories of the root. Paths passed of to the `restrictions` parameter will not show up in the client view, and it is impossible to navigate into these subdirectories. The `filetypes` parameter takes a vector of file extensions to filter the output on, so that the client is only presented with these filetypes. The `hidden` parameter toggles whether hidden files should be visible or not. Whenever a file or folder choice is made the resulting files/folder will be accessible in the input variable with the id given in the parameters. This value should probable be run through a call to one of the parser (`shinyFiles-parsers()`) in order to get well formatted paths to work with.

### Value

A reactive observer that takes care of the server side logic of the filesystem connection.

### Note

The syntax for this version has changed with version 0.4.0. Prior to that version the output of `shinyFileChoose()` should be assigned to the output object. This is no longer the case and doing so will result in an error. In newer versions the function returns an observer which can be ignored for the most part, or assigned to a variable if there needs to be interactions with it later on.

### See Also

Other shinyFiles: `shinyFiles-buttons`, `shinyFiles-parsers`, `shinyFilesExample`

### Examples

    ## Not run:
    # File selections
    ui <- shinyUI(bootstrapPage(
      shinyFilesButton('files', 'File select', 'Please select a file', FALSE)
    ))
    server <- shinyServer(function(input, output) {
      shinyFileChoose(input, 'files', roots=c(wd='.'), filetypes=c('', 'txt'),
                      defaultPath='', defaultRoot='wd')
    })

    runApp(list(
      ui=ui,
      server=server
    ))

    ## End(Not run)

    ## Not run:
    # Folder selections
    ui <- shinyUI(bootstrapPage(
      shinyDirButton('folder', 'Folder select', 'Please select a folder', FALSE)
    ))
    server <- shinyServer(function(input, output) {
      shinyDirChoose(input, 'folder', roots=c(wd='.'), filetypes=c('', 'txt'))
    })

    runApp(list(
      ui=ui,
      server=server
    ))

    ## End(Not run)

    ## Not run:
    # File selections
    ui <- shinyUI(bootstrapPage(
      shinySaveButton('save', 'Save', 'Save as...')
    ))
    server <- shinyServer(function(input, output) {
      shinyFileSave(input, 'save', roots=c(wd='.'))
    })

    runApp(list(
      ui=ui,
      server=server
    ))

    ## End(Not run)

[Package shinyFiles version 0.7.1 Index]