title: R shiny problem calling my function with a button
body: <p>I have defined a function in the server as &quot; RunPlot &lt;- function(tickers, sharesVec, FromDate, ToDate)&quot;. The function should return a single numerical value. I want to output this value by clicking on the button &quot;Go&quot;, but when I click on the button, nothing happens. Also, I have tried calling this function in a separate script and everything worked so there is no error inside the function. Here is my code:</p>
  <p>UI</p>
  <pre><code>
  shinyUI(fluidPage(
  
      titlePanel(&quot;test&quot;),
  
      sidebarLayout(
          sidebarPanel(
              actionButton(&quot;Go&quot;, &quot;Go!&quot;)
          ),
  
          mainPanel(
              textOutput(&quot;TEST&quot;)
          )
      )
  ))
  </code></pre>
  <p>Server</p>
  <pre><code>library(shiny)
  library(quantmod)                            
  library(PerformanceAnalytics)
  
  shinyServer(function(input, output) {
  
      RunPlot &lt;- function(tickers, sharesVec, FromDate, ToDate){
          
          PortfolioPrices &lt;- NULL 
          for (i in tickers){
              PortfolioPrices &lt;- cbind(PortfolioPrices, 
                                       getSymbols.yahoo(i, from = FromDate, to = ToDate,             
                                                        auto.assign = F)[,6])  
          }  
          
          TempValue &lt;- PortfolioPrices[1,]
          MarketValue &lt;- sharesVec*TempValue
          Weights &lt;- MarketValue/sum(MarketValue) #Now have Weights AND Tickers vectors
          
          #C) Compute Portfolio Returns
          for (j in 1:ncol(PortfolioPrices)){          #Data cleaning                                                      
              for (i in 1:nrow(PortfolioPrices)){
                  if (is.na(PortfolioPrices[i,j]) == TRUE){
                      PortfolioPrices[i,j] &lt;- PortfolioPrices[i-1,j]
                  }
              }
          }
          
          Rf &lt;- getQuote(&quot;^TNX&quot;, src = &quot;yahoo&quot;)[1,2]/100
          AssetsReturns &lt;- na.omit(ROC(PortfolioPrices, type = &quot;discrete&quot;))                                  
          PortfolioReturns &lt;- Return.portfolio(AssetsReturns, weights = Weights)                             
          PortfolioAnnualizedReturns &lt;- table.AnnualizedReturns(PortfolioReturns, Rf = Rf/252)                            
          colnames(PortfolioAnnualizedReturns) &lt;- &quot;Portfolio&quot;
          
          #D) Compute Benchmark Returns
          SP500 &lt;- getSymbols.yahoo(&quot;SPY&quot;, from = FromDate, to = ToDate, auto.assign = F)[,6]       
          SP500Returns &lt;- na.omit(ROC(SP500, type = &quot;discrete&quot;))                                             
          SP500AnnualizedReturns &lt;- table.AnnualizedReturns(SP500Returns, Rf = Rf/252)  
          colnames(SP500AnnualizedReturns) &lt;- &quot;S&amp;P500&quot;
          
          SPTSX &lt;- getSymbols.yahoo(&quot;XIC.TO&quot;, from = FromDate, to = ToDate, auto.assign = F)[,6]   
          SPTSXReturns &lt;- na.omit(ROC(SPTSX, type = &quot;discrete&quot;))                                             
          SPTSXAnnualizedReturns &lt;- table.AnnualizedReturns(SPTSXReturns, Rf = Rf/252) 
          colnames(SPTSXAnnualizedReturns) &lt;- &quot;S&amp;P/TSX&quot;
          
          MSCIIMI &lt;- getSymbols.yahoo(&quot;XEF.TO&quot;, from = FromDate, to = ToDate, auto.assign = F)[,6]   
          MSCIIMIReturns &lt;- na.omit(ROC(MSCIIMI, type = &quot;discrete&quot;))                                             
          MSCIIMIAnnualizedReturns &lt;- table.AnnualizedReturns(MSCIIMIReturns, Rf = Rf/252) 
          colnames(MSCIIMIAnnualizedReturns) &lt;- &quot;MSCI EAFE IMI&quot;
          
          MSCIEME &lt;- getSymbols.yahoo(&quot;XEC.TO&quot;, from = FromDate, to = ToDate, auto.assign = F)[,6]   
          MSCIEMEReturns &lt;- na.omit(ROC(MSCIEME, type = &quot;discrete&quot;))                                             
          MSCIEMEAnnualizedReturns &lt;- table.AnnualizedReturns(MSCIEMEReturns, Rf = Rf/252) 
          colnames(MSCIEMEAnnualizedReturns) &lt;- &quot;MSCI Emerging Markets&quot;
          
          #E) Format Data
          PortfolioCumReturns &lt;- fortify.zoo(PortfolioReturns+1)                                             
          SP500CumReturns &lt;- fortify.zoo(SP500Returns+1)
          SPTSXCumReturns &lt;- fortify.zoo(SPTSXReturns+1)
          MSCIIMICumReturns &lt;- fortify.zoo(MSCIIMIReturns+1)
          MSCIEMECumReturns &lt;- fortify.zoo(MSCIEMEReturns+1)
          
          for (j in 2:nrow(PortfolioCumReturns)){                                                            
              PortfolioCumReturns[j,2] &lt;- PortfolioCumReturns[j-1,2]*PortfolioCumReturns[j,2]
          }
          for (j in 2:nrow(SP500CumReturns)){
              SP500CumReturns[j,2] &lt;- SP500CumReturns[j-1,2]*SP500CumReturns[j,2]
          }
          for (j in 2:nrow(SPTSXCumReturns)){
              SPTSXCumReturns[j,2] &lt;- SPTSXCumReturns[j-1,2]*SPTSXCumReturns[j,2]
          }
          for (j in 2:nrow(MSCIIMICumReturns)){
              MSCIIMICumReturns[j,2] &lt;- MSCIIMICumReturns[j-1,2]*MSCIIMICumReturns[j,2]
          }
          for (j in 2:nrow(MSCIEMECumReturns)){
              MSCIEMECumReturns[j,2] &lt;- MSCIEMECumReturns[j-1,2]*MSCIEMECumReturns[j,2]
          }
          
          PortfolioCumReturns &lt;- PortfolioCumReturns - 1                                                      
          SP500CumReturns &lt;- SP500CumReturns - 1
          SPTSXCumReturns &lt;- SPTSXCumReturns - 1
          MSCIIMICumReturns &lt;- MSCIIMICumReturns - 1
          MSCIEMECumReturns &lt;- MSCIEMECumReturns - 1
          
          ### Results ###
          
          ReturnsTABLE &lt;- cbind(PortfolioAnnualizedReturns,SP500AnnualizedReturns,SPTSXAnnualizedReturns,MSCIIMIAnnualizedReturns,MSCIEMEAnnualizedReturns)
          
          Benchmark &lt;- getSymbols.yahoo(&quot;^GSPC&quot;, from = FromDate, to = ToDate, auto.assign = F)[,6]   
          BenchmarkReturns &lt;- na.omit(ROC(Benchmark, type = &quot;discrete&quot;))  
          BETA &lt;- CAPM.beta(PortfolioReturns, BenchmarkReturns, Rf/252)
          ALPHA &lt;- CAPM.jensenAlpha(PortfolioReturns, BenchmarkReturns, Rf/252)
          
          return(BETA)   
          
      }
  
  
  observeEvent(input$Go, {
      BETA &lt;- RunPlot(&quot;MSFT&quot;,5,as.Date(&quot;2019-12-31&quot;),as.Date(&quot;2020-12-31&quot;))
  })
  output$TEST &lt;- renderText({
      paste(BETA)
  })
      
  })
  </code></pre>
  <p>Any kind of help would be appreciated!</p>