2016-07-29 3 views
0

入力に応じて計算時間が長い光沢のあるアプリがあります。私は、計算が完了したとき(と前にないとき)にメインパネルにテキストを表示することが可能かどうか疑問に思っています。R shiny hide計算時間中のmainPanelオブジェクト

簡単な例を作ってみましょう。私はSys.sleep()で長い計算をシミュレート:目標は次のようになり

# Define UI for application that draws a histogram 

ui <- shinyUI(fluidPage(

# Application title 
    titlePanel("Old Faithful Geyser Data"), 

# Sidebar with a slider input for number of bins 
    sidebarLayout(
     sidebarPanel(
     sliderInput("bins", 
        "Number of bins:", 
        min = 1, 
        max = 50, 
        value = 30) 
    ), 

     # Show a plot of the generated distribution 
     mainPanel(
     h3('This is an example'), 
     plotOutput("distPlot") 
    ) 
    ) 
)) 

# Define server logic required to draw a histogram 
server <- shinyServer(function(input, output) { 

    output$distPlot <- renderPlot({ 
     # generate bins based on input$bins from ui.R 
     x <- faithful[, 2] 
     bins <- seq(min(x), max(x), length.out = input$bins + 1) 

     # draw the histogram with the specified number of bins 
     hist(x, breaks = bins, col = 'darkgray', border = 'white') 
     Sys.sleep(5) 
    }) 
}) 

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

、計算がないの前に行われると同時に、テキスト「これは一例です」を表示するように。 私はテキストを何らかの形で反応させる必要があると思いますが、これまで私はこれに対する解決策を見つけていませんでした。たぶんconditionalPanelがそれを行うことができますが、どのようにして計算時間をその状態にすることができますか?何か案は?

答えて

1

これはあなたが探しているものでしょうか? distPlotのイベントを観察した後の反応としてのテキスト変数

library(shiny) 
# Define UI for application that draws a histogram 

ui <- shinyUI(fluidPage(

    # Application title 
    titlePanel("Old Faithful Geyser Data"), 

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
    sidebarPanel(
     sliderInput("bins", 
        "Number of bins:", 
        min = 1, 
        max = 50, 
        value = 30) 
    ), 
    # Show a plot of the generated distribution 
    mainPanel(
     textOutput('text1'), 
     plotOutput("distPlot") 
    ) 
) 
)) 

# Define server logic required to draw a histogram 
server <- shinyServer(function(input, output) { 
    output$distPlot <- renderPlot({ 
    # generate bins based on input$bins from ui.R 
    x <- faithful[, 2] 
    bins <- seq(min(x), max(x), length.out = input$bins + 1) 
    # draw the histogram with the specified number of bins 
    hist(x, breaks = bins, col = 'darkgray', border = 'white') 
    Sys.sleep(2) 

    }) 
    observeEvent(plotOutput("distPlot"), { 
    output$text1 <- renderText({ paste("Number of bins:", input$bins)}) 
    }) 
    }) 

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

まさに!ありがとうございました –