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

having issue running shiny and promises #10

Closed
felloumi opened this issue Dec 5, 2017 · 11 comments
Closed

having issue running shiny and promises #10

felloumi opened this issue Dec 5, 2017 · 11 comments

Comments

@felloumi
Copy link

felloumi commented Dec 5, 2017

Hi Joe,

I looked at your slides at https://www.dropbox.com/s/2gf6tfk1t345lyf/async-talk-slides.pdf?dl=0 and run the following similar code:

library(promises)
library(shiny) # async version
library(future)
plan(multiprocess) # use another R process/running in the background
#availableCores() # 8

longRunningFunction <- function(value) {
Sys.sleep(10)
return(value)
}

ui <- fluidPage(

Application title

titlePanel("Testing shiny@async, future and promises"),

actionButton("train", "slowest function"),
verbatimTextOutput("summary"),

actionButton("option", "Display 20"),
verbatimTextOutput("result")
)

server <- function(input, output,session) {

model <- eventReactive(input$train, {

# longRunningFunction(5)
future(longRunningFunction(5))

})

output$summary <- renderPrint({

#model()
model() %...>% print()

})

model2 <- eventReactive(input$option, {

return(20)

})

output$result <- renderPrint({

print(model2())

})
}

Run the application

shinyApp(ui = ui, server = server)

I expected that when I click on the first button (slowest function) and then immediately click on the second button to display 20 however it happened after I got the message from the first button. I thought that the first function will be run on the background. I am not sure if some thing is wrong with my code. I appreciate any clarification on this.

Thanks,

FE

@jcheng5
Copy link
Member

jcheng5 commented Dec 5, 2017

That used to be true, but we have gone out of our way to disallow that. We don't process new input messages (or invalidateLater timer events) for a session unless/until all previous input messages have been fully processed. If we didn't do this it would be difficult to reason about reactive code because you would have inputs changing state in the middle of async operations. The goal of the async functionality is less about reducing latency for a single session, and more about preventing multiple sessions from blocking each other.

@felloumi
Copy link
Author

felloumi commented Dec 6, 2017

Ok thanks. I have another issue rendering a table using future/promises. Here is the example:

library(promises)
library(shiny) # async version
library(future)
plan(multiprocess) # use another R process/running in the background
#availableCores() # 8
library(DT)

longRunningFunction <- function(value) {
  Sys.sleep(10)
  return(value)
}

rr <- function() {
  x=read.delim("~/file.txt") # any text tab delimited file
  DT::datatable(x)
}
# 
ui <- fluidPage(
   
   # Application title
   titlePanel("Testing shiny@async, future and promises"),
   
   #  
   actionButton("train", "slowest function"), 
   verbatimTextOutput("summary"),
   
   actionButton("option", "Table"), 
   DT::dataTableOutput("result")
   )


# Define server logic required to draw a histogram
server <- function(input, output,session) {
   
  model <- eventReactive(input$train, { 
    
    # longRunningFunction(5)
    future(longRunningFunction(5))
    
  }) 
  
  output$summary <- renderPrint({ 
    
    model()
    # model() %...>% print()
    
  })
  
  model2 <- eventReactive(input$option, { 
    
    #rr()
    future(rr())
    
  }) 
  
  output$result <- DT::renderDataTable({ 
    
    model2()
    #model2() %...>% View()
  }) 
  
   
  
  
}

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

Running the app and clicking on command table gives an error:
screen shot 2017-12-06 at 3 11 15 pm

The code run perfectly without future. Any solution for the issue?

@jcheng5
Copy link
Member

jcheng5 commented Dec 6, 2017

DT isn't ready for promises yet, I have to make some changes there. Most htmlwidget packages will not need modifications to work for their render functions to work with promises, but DT does a lot of custom stuff.

@jcheng5
Copy link
Member

jcheng5 commented Feb 16, 2018

There's now an async branch for DT, FYI.

@jcheng5 jcheng5 closed this as completed Feb 16, 2018
@felloumi
Copy link
Author

felloumi commented Feb 16, 2018 via email

@boxiangliu
Copy link

Currently the async branch does not seem to function. The datatable output is blank.

@dmenne
Copy link

dmenne commented Jun 25, 2018

It works for me on Window, not on Ubuntu (blank) as @boxiangliu

dmenne added a commit to dmenne/breathtestshiny that referenced this issue Jun 25, 2018
@PauloJhonny
Copy link

I'm having the same issue when I try to use DT with promises, as @felloumi :

'Error in datatable: 'data' must be 2-dimensional (e.g. data frame or matrix)'.

@dmenne
Copy link

dmenne commented Jun 27, 2018

Try to use the github version of htmlwidgets

@PauloJhonny
Copy link

Thank you, @dmenne. I just installed the dev version of htmlwidgets, but it didn't work. So, I tried to install the dev version of DT as well, and it seems it worked. At least the async datatable output show up.

@dmenne
Copy link

dmenne commented Jun 27, 2018

Sorry, my error. I should have said "of DT". Glad it worked.

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

5 participants