2017-02-19 33 views
1

嗨我想從服務器端發送一個「虛假」輸入更新後的一些計算。換句話說,我想控制輸出更新傳播的順序。如何控制閃亮的更新傳播順序

例如,在下面的腳本我需要更新在第二observeEvent的Sys.sleep後輸出$文字:

library(shiny) 

ui <- fluidPage(

    titlePanel("PLOP"), 

    sidebarLayout(
     sidebarPanel(
     selectInput("variable", "Variable:", 
        c("Cylinders" = "cyl", 
         "Transmission" = "am", 
         "Gears" = "gear")), 
     actionButton("press","press") 
    ), 

     mainPanel(
     textOutput("text") 
    ) 
    ) 
) 

server <- function(input, output) { 

    output$text <- renderText({ 
    input$press 
    message("rendertext at ",Sys.time()) 
    paste(input$variable,Sys.time())}) 

    observeEvent(input$variable, 
       message("variable is edited at ",Sys.time()) 
       ) 
    observeEvent(input$press,{ 
       message("button is presed at ",Sys.time()) 
       # lot of stuff 
       Sys.sleep(2) 
       message("end calculation at ",Sys.time()) 
       # AND NOW I would like to send a "false" input$variable update 
       # I dont want to change input$variable, but I need to rerun everything which use input$variable 
       # (....) for example : changing output$text but AFTER the Sys.sleep call 


}) 




} 

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

非常感謝

回答

1

正如mentionted在我的評論:在?oberserveEvent你可以設置一個參數priority。具有較高優先級號碼的功能將首先被評估。