2013-12-10 24 views
8

में देरी निष्पादन क्या यह संभव है कि विंडोज़ सेवाओं में देरी से शुरू होने की तरह देरी हुई फैशन में आरशनी ऐप के कुछ हिस्सों को निष्पादित किया जाए?आर चमकदार ऐप

मुझे विस्तृत करने दें।

मेरे पास टैब के साथ एक चमकदार ऐप है। प्रत्येक टैब में साइडबार पैनल पर रेडियो बटन का एक समूह होता है। प्रत्येक रेडियो बटन पर क्लिक करने से एक रिपोर्ट सामने आती है। मेरा सेट अप इस तरह के रूप में सरल है।

हालांकि जब मैं हर बार ऐप लोड करता हूं और जब पहला टैब ऑटो रेंडर किया जाता है, तो इस टैब के नीचे सभी रेडियो बटन से जुड़े सभी रिपोर्ट निष्पादित की जाती हैं और फिर पहला रेडियो बटन चुना जाता है और इसकी सहसंबंध रिपोर्ट प्रदर्शित होती है। इस पूरी प्रक्रिया में लगभग 10-11 सेकंड लगते हैं जिन्हें मैं नीचे लाना चाहता हूं।

सर्वर शुरू होने के दौरान, मैंने बस अपनी myData.RData फ़ाइल को वैश्विक में पढ़ा। आर। तो सर्वर प्रारंभ के दौरान सभी डेटा पूर्व-प्राप्त (और मुझे स्मृति में रखा जाता है) है। जब टैब को ध्यान में लाया जाता है तो क्या होता है यह है कि myData.RData से डेटा.फ्रेम पढ़े जाते हैं और ggplots (renderPlot) और तालिकाओं (renderText) की एक श्रृंखला को कॉल किया जाता है।

क्या कोई तरीका है कि मैं कुछ सेकंड के भीतर पहली रिपोर्ट प्रस्तुत कर सकता हूं और फिर अन्य ggplots और तालिकाओं को निष्पादित करने के लिए आगे बढ़ सकता हूं? मैं प्रतिक्रियाशीलता कंडक्टर और अलगाव के माध्यम से गया था लेकिन यह नहीं पता था कि कौन सा समाधान मेरी समस्या को फिट करता है।

या क्या कोई और तरीका है जिससे मैं लोड (और रीफ्रेश) समय को तेज कर सकता हूं?

कुछ कोड में मदद करने के मुद्दे को समझने ..

# In server.R 

    library(shiny) 
    library(plyr) 
    library(ggplot2) 
    library(grid) 

    source("a.R", local=TRUE) 
    source("b.R", local=TRUE) 

    shinyServer(function(input, output) { 

     # The below two lines represent a report pair to me. So I have a Bar plot and the associated Table report. 
     output$wSummaryPlot = renderPlot({ print(drawBarPlotA("Bar Plot A")) }) 
     output$wSummaryTable = renderText({ tableA() }) 

     # There are about 20 such pairs in server.R 

     # Please note that I am including other R file by "source". The first two lines shows that. Don't know if that is what is causing the problem. 

     # The drawBarPlotA and tableA are functions defined in one of the source files which are included above. 
     # There are 5 such files which are included similarly. 
    }) 

    # In ui.R 
    shinyUI(pageWithSidebar(
     headerPanel(windowTitle = "Perfios - DAS", addHeader()), 

     sidebarPanel(
      conditionalPanel(condition = "input.reportTabs == 1 && input.reportType == 'reportTypeA'", 
         wellPanel(radioButtons("showRadio", strong("Attributes:"), 
               c("Analysis A" = "a", 
                "Analysis B" = "b", 
                "Analysis C" = "c", 
                "Analysis D" = "d", 
                "Analysis E" = "e", 
                "Analysis F" = "f" 
               ))) 
     )) 

     mainPanel(
      tabPanel("A", value = "1", 
       conditionalPanel(condition = "input.reportType == 'reportTypeA'", 
            conditionalPanel(condition = "showRadio == 'X'", 
                plotOutput("wSummaryPlot"), h4("Summary:"), verbatimTextOutput("wSummaryTable")) 


     # Many such element here to accomodate for those 20 reports... 
    ))) 
)) 

# In drawBarPlotA 
drawBarPlotA = function(mainText) { 
    ggplot(data, aes(variable, value, fill = some_fill)) + 
    geom_bar(stat = "identity", position = "dodge", color = "grey") + 
    ylab("Y Label") + 
    xlab(NULL) + 
    theme_bw() + 
    ggtitle(mainText) + 
    scale_fill_brewer(palette = "Set1") + 
    annotate("text", x = 1.2, y = 0, label = "Copyright...", size = 4) + 
    theme(axis.text.x = element_text(angle = 45, hjust = 1, size = "12", face = "bold"), 
      axis.text.y = element_text(size = "12"), 
      plot.title = element_text(size = "14", vjust = 3, face = "bold")) 
} 

tableA = function() { 
    # This is a data.frame which is returned 
    data 
} 
+0

आप हमें अपने 'server.R',' ui.R' और किसी भी अन्य आवश्यक कोड दिखा सकते हैं? – MadScone

+0

मैंने एक कोड स्निपेट जोड़ा है। उम्मीद है की यह मदद करेगा। धन्यवाद। – shingav

उत्तर

9
shinyServer(function(input, output, session) { 
    values <- reactiveValues(starting = TRUE) 
    session$onFlushed(function() { 
    values$starting <- FALSE 
    }) 

    output$fast <- renderText({ "This happens right away" }) 
    output$slow <- renderText({ 
    if (values$starting) 
     return(NULL) 
    "This happens later" 
    }) 
}) 
+0

बहुत बहुत धन्यवाद जो। – shingav

+0

क्या यह किसी भी मौके पर केवल प्रस्तुत करने के लिए लागू है? मैं सत्र और ऑनफ्लूज्ड इवेंट्स पर किसी दस्तावेज़ को नहीं ढूंढ सका। मेरे रेंडरप्लॉट में कोई सुधार नहीं है। – shingav

+0

@RohithVenkatakrishna नहीं, मुझे नहीं लगता कि यह 'renderText() 'से जुड़ा हुआ है; आप किसी भी 'रेंडर ???' कार्यों का उपयोग कर सकते हैं। –

संबंधित मुद्दे