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

JOSS Review: Improve use of reactivity in application #4

Closed
elimillera opened this issue Jul 13, 2021 · 0 comments
Closed

JOSS Review: Improve use of reactivity in application #4

elimillera opened this issue Jul 13, 2021 · 0 comments

Comments

@elimillera
Copy link
Contributor

More of a design question, this won't hold up a JOSS review. On of the major design tools in shiny is using reactive objects to avoid having complex server functions. Right now the server functions look like this:

server <- function(input, output) {
  <filepaths, etc>
  output$table <- renderTable({
    if(someCond) {
      return()
    }
    if(input$button > 0) {
      <somethingToRender>
    })}

While this is functioning fine, generally it is a good idea to separate the derivation of your objects from the server function and use the req function instead of something like input$button > 0. So the functionality would become something like this:

server <- function(input, output) {
  <filepaths, input data, etc>

  # deriveDescTable would return our table we want to display
  descTable <- reactive({
    # This would prevent it from being rendered if the submit button hasn't been pressed or there isn't data
    req(input$submitButton)
    req(input$file1)
    deriveDescTable(filepath, otherParams)
    })

  output$descTab <- renderTable(descTab)
}

I'm also seeing the use of Sys.sleep in certain places. It looks like this might be to wait for some calculations to complete but this will also remove the need for that.

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

2 participants