2013-07-17 15 views
8

私は多くのパラメータを持つアプリケーションを持っています。各パラメータには細粒度があり、目的のものに痛みを感じさせます。これにより、リアクション部分が常に計算され、物事が遅くなります。上記の問題を解決したsubmitButtonを追加しましたが、次に別の問題が発生しました。光沢のある反応性

以下は、私が構築するフレームワークの単純な複製です。パラメータの入力には、1から1000までの数字が入ります。これは、必要なサンプルを示します。私がやりたいことは、上記のことを行うことができるだけでなく、同じパラメータセットで再サンプリングできることです。送信ボタンを追加した後に何が起こっているかは、最初に再サンプリングしてから更新ボタンをクリックしない限り、再サンプルボタンを操作不能にすることです。

別々に動作させるためのアイデアはありますか?

shinyServer(function(input, output) { 
    getY<-reactive({ 
    a<-input$goButton 
    x<-rnorm(input$num) 
    return(x) 
    }) 

    output$temp <-renderPlot({ 
    plot(getY()) 
    }, height = 400, width = 400) 
}) 

shinyUI(pageWithSidebar(
    headerPanel("Example"), 
    sidebarPanel(
    sliderInput("num", 
      "Number of Samples", 
      min = 2, 
      max = 1000, 
      value = 100), 
    actionButton("goButton", "Resample"), 
    submitButton("Update View")   
), 
    mainPanel(
    tabsetPanel(  
     tabPanel("Heatmap", 
       plotOutput("temp") 
    ), 
     tabPanel("About"),  
     id="tabs" 
    )#tabsetPanel  
)#mainPane; 
)) 

ジョーの回答に基づいてEDIT:

shinyServer(function(input, output) { 
    getY<-reactive({ 

    isolate({a<-input$goButton 
     x<-rnorm(input$num) 
     return(x)}) 
    }) 

    output$temp <-renderPlot({ 
    b<-input$goButton1 
    plot(getY()) 
    }, height = 400, width = 400) 
}) 

shinyUI(pageWithSidebar(
    headerPanel("Example"), 
    sidebarPanel(
    sliderInput("num", 
      "Number of Samples", 
      min = 2, 
      max = 1000, 
      value = 100), 
    actionButton("goButton", "Resample"), 
    actionButton("goButton1","Update View")   
), 
    mainPanel(
    tabsetPanel(  
     tabPanel("Heatmap", 
       plotOutput("temp") 
    ), 
     tabPanel("About"),  
     id="tabs" 
    )#tabsetPanel  
)#mainPane; 
)) 
+0

あなたはコードを書いています。鍵の演算子の周りの*行間の空白のトン* –

+0

投稿する前にコードを次回編集すると、私はコピーとペーストから急いでいました。 – user1234440

答えて

4
  • 変化のgetY actionButton
  • にすべてが、最初の行は、単離物に包まれ({...})
  • 変化のsubmitButtonよう
  • 新しいアクションボタンを読み込むために、renderPlotの内部に行を追加します。
+0

私はあなたの提案を試みました。今私は何を押しても初期化後にプログラムが停滞しているようです。私はコードの更新版を追加しました。 – user1234440

+0

@ user1234440すべて**最初の行** –

9

答えは上記のコメントでジョー・チェンによって与えられたが、OPは困難、それを理解していたことを見て、私は記録のために、明示的に以下のことを書きました:

# ui.R 

library("shiny") 
shinyUI(
    pageWithSidebar(
    headerPanel("Example") 
    , 
    sidebarPanel(
     sliderInput("N", "Number of Samples", min = 2, max = 1000, value = 100) 
     , 
     actionButton("action", "Resample") 
    ) 
    , 
    mainPanel(
     tabsetPanel(  
     tabPanel("Plot", plotOutput("plotSample")) 
     , 
     id = "tabs1" 
    ) 
    ) 
) 
) 

# server.R 

library("shiny") 
shinyServer(
    function(input, output, session) { 
    Data <- reactive({ 
     input$action 
     isolate({ 
      return(rnorm(input$N)) 
      return(x) 
     }) 
    }) 
    output$plotSample <-renderPlot({ 
     plot(Data()) 
    } , height = 400, width = 400 
) 
}) 

注反応性内部入力$作用を有すること()は、actionButtonのinputIDであり、プロットの新しいレンダリングを開始するのに十分です。したがって、actionButtonは1つだけ必要です。

関連する問題