Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Inputs for loading additional data on the "files" tab #4

Open
jwildfire opened this issue Aug 11, 2017 · 8 comments
Open

Add Inputs for loading additional data on the "files" tab #4

jwildfire opened this issue Aug 11, 2017 · 8 comments
Assignees
Milestone

Comments

@jwildfire
Copy link
Contributor

jwildfire commented Aug 11, 2017

Add inputs to the .instructions section of the files tab that allow users to add files to the codebook.

  • select either a single file from their computer add it to the Files tab
  • select a directory from their computer and automatically add all supported data type (e.g. sas7bdat, rdata, csv) to the Files Tab
  • clear all current inputs from the codebook
@jwildfire jwildfire changed the title Create Load Data Tab Add Inputs for loading additional data on the "files Aug 12, 2017
@jwildfire jwildfire changed the title Add Inputs for loading additional data on the "files Add Inputs for loading additional data on the "files" tab Aug 12, 2017
@jwildfire
Copy link
Contributor Author

There are a few steps to figure out.

  1. Once the files tab is drawn server.R add the buttons to the tab (this isn't done by the javascript library)
  2. When a button is clicked, the file or files should be added to the files table (this requires passing info from client -> server -> client)

@jwildfire
Copy link
Contributor Author

@jwildfire
Copy link
Contributor Author

jwildfire commented Aug 12, 2017

Pretty sure we want to use observeEvent() for these. This example is close, but we need to trigger on a custom js from codebook.js ("renderComplete" or whatever we choose to call it) instead of a named input (input$go):

  shinyApp(
    ui = basicPage(actionButton("go", "Go")),
    server = function(input, output, session) {
      observeEvent(input$go, {
        insertUI("#go", "afterEnd",
                 actionButton("dynamic", "click to remove"))

        # set up an observer that depends on the dynamic
        # input, so that it doesn't run when the input is
        # created, and only runs once after that (since
        # the side effect is remove the input from the DOM)
        observeEvent(input$dynamic, {
          removeUI("#dynamic")
        }, ignoreInit = TRUE, once = TRUE)
      })
    }
  )
}

EDIT: No longer convinced observeEvent() is the way to go. Not clear to me if you can trigger this based on an output changing state, or if it has to be an input. Not able to find an example where this triggers on an arbitrary js event (although seems like it should be doable ...)

@jwildfire
Copy link
Contributor Author

jwildfire commented Aug 12, 2017

This looks like a good option for js -> R -> js rendering. Can be used to trigger an update in the files table once a new file is added.

@jwildfire
Copy link
Contributor Author

And this might be the way to add content after the initial loads. Can be used to add the file upload buttons after the explorer Shiny output is validated.

@jwildfire
Copy link
Contributor Author

jwildfire commented Aug 12, 2017

Simple implementation of part #1 ("Once the files tab is drawn server.R adds the buttons to the tab") done like so:

    Sys.sleep(1)
    insertUI(
      selector="div.explorer div.instructions.section",
      where="beforeEnd",
      ui=fileInput('datafile','Upload a file',accept = c('.sas7bdat','.csv'))
    )

Need to add in some of bootstrap's CSS to make it look decent and would be better to trigger on a call back, but all things considered, waiting for a second works reasonably well ...

@jwildfire
Copy link
Contributor Author

One is basically good to go. Going to create separate issues for part 2 below:

  1. Once the files tab is drawn server.R add the buttons to the tab (this isn't done by the javascript library)
  2. When a button is clicked, the file or files should be added to the files table (this requires passing info from client -> server -> client)

@jwildfire jwildfire added this to the v0.2.0 milestone Aug 21, 2017
@jwildfire jwildfire self-assigned this Aug 21, 2017
@jwildfire jwildfire modified the milestones: v0.2.0, v0.3.0 Oct 9, 2017
@jwildfire
Copy link
Contributor Author

Alas, bumping from v0.2.0. Sys.sleep() didn't play nice with interactivity. Seems like we probably need to use a more typical javascript event workflow to do this. Will tackle in a future version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant