title: Using 2 separate plotly (or ggplotly) plots in a tabsetPanel in a shiny app
body: <p>I am using the <code>plotly</code> package to produce two plots styled through their <code>ggplotly</code> integration based on a user's inputs. the user accesses each plot by using the tabset panel choice. Unfortunately, in testing, I was not able to use the <code>plotly</code> package to produce both graphs without causing my <code>R</code> instance to crash. </p>
  
  <p><a href="http://i.stack.imgur.com/JsXSX.png" rel="nofollow">UI with normal <code>ggplot2</code> functionality</a></p>
  
  <p>here's the data as suggested by the comments:</p>
  
  <pre><code>generationData = read.csv("data/statedata.csv", #"https://docs.google.com/spreadsheets/d/1ZbDI31sSKatBoEVKo70TV_A4VwCBHK4pIoCWXB7yfx0/pub?gid=192701245&amp;single=true&amp;output=csv", 
                        header = TRUE) #read csv file
  generationDataCleaned = generationData[!(is.null(generationData$Name) | generationData$Name==""), ]
  
  statenames = as.character(generationDataCleaned$Name) 
  row.names(generationDataCleaned) = statenames
  </code></pre>
  
  <p><code>result()</code> is a reactive function to calculate the result data frame that the plot uses</p>
  
  <pre><code>result &lt;- reactive({
  state = input$stateInput
  pctCoal = input$Coal / 100
  if(state == "") {
    #handle onload
    print("it was blank!")
    state = "Alabama"
    pctCoal = 15 / 100 
    }
       baseCoal_Energy = generationDataCleaned[state, "Coal.Steam.Electric.Generation..MWh."]
       baseNGCC_Energy = generationDataCleaned[state, "NGCC.Electric.Generation..MWh."]
  
  totalEnergy = sum(baseCoal_Energy,
                    baseNGCC_Energy
  )
  baseEnergy = totalEnergy
  
  coalEnergy_Reduction = (pctCoal) * baseCoal_Energy
  
  newCoal_Energy = (1 - pctCoal) * baseCoal_Energy
  newNGCC_Energy =  baseNGCC_Energy + coalEnergy_Reduction
  
  newEnergy = newCoal_Energy + newNGCC_Energy
  Energy_Frame &lt;- c(baseEnergy, newEnergy)
  
  #Emissions Rate
  baseCoal_CO2_Rate = generationDataCleaned[state, "Coal.Steam.Emission.Rate..lb.MWh."]
  baseNGCC_CO2_Rate = generationDataCleaned[state, "NGCC.Emission.Rate..lb.MWh."]
  
  totalCO2_Rate = sum(baseCoal_CO2_Rate,
                      baseNGCC_CO2_Rate
                      )
  baseCO2_Rate = totalCO2_Rate
  
  coalCO2_Rate_Reduction = (pctCoal) * baseCoal_CO2_Rate
  
  newCoal_CO2_Rate = (1 - pctCoal) * baseCoal_CO2_Rate
  
  newNGCC_CO2_Rate =  baseNGCC_CO2_Rate + coalEnergy_Reduction * baseNGCC_CO2_Rate / baseNGCC_Energy
  
  newCO2_Rate = newCoal_CO2_Rate + newNGCC_CO2_Rate
  
  CO2_Rate_Frame &lt;- c(baseCO2_Rate, newCO2_Rate) 
  
  #Emissions Mass
  
  baseCoal_CO2_Mass = generationDataCleaned[state, "Coal.Steam.Carbon.Dioxide.Emissions..tons."]
  baseNGCC_CO2_Mass = generationDataCleaned[state, "NGCC.Carbon.Dioxide.Emissions..tons."]
  
  
  totalCO2_Mass = sum(baseCoal_CO2_Mass,
                      baseNGCC_CO2_Mass
                      )
  baseCO2_Mass = totalCO2_Mass
  
  coalCO2_Mass_Reduction = (pctCoal) * baseCoal_CO2_Mass
  
  newCoal_CO2_Mass = (1 - pctCoal) * baseCoal_CO2_Mass
  
  newNGCC_CO2_Mass =  baseNGCC_CO2_Mass + coalEnergy_Reduction * baseNGCC_CO2_Mass / baseNGCC_Energy
  
  newCO2_Mass = newCoal_CO2_Mass + newNGCC_CO2_Mass
  
  CO2_Mass_Frame &lt;- c(baseCO2_Mass, newCO2_Mass) 
  
  name_Frame &lt;- c("Base", "New")
  
  result &lt;- data.frame(name_Frame, Energy_Frame, CO2_Rate_Frame, CO2_Mass_Frame)
  
  colnames(result) &lt;- c("Name", "Energy", "Rate", "Mass")
  
  result
  })
  </code></pre>
  
  <p><code>ui.R</code></p>
  
  <pre><code>column(8,
         tabsetPanel(type = "tabs", 
                     id = "tabset1",
                     tabPanel("Rate", value = "Rate", plotlyOutput("ratePlot")),
                     tabPanel("Mass", value = "Mass", plotlyOutput("massPlot"))#, plotOutput("massPlot"))
                    )
  </code></pre>
  
  <p><code>server.R</code></p>
  
  <pre><code>output$ratePlot &lt;- renderPlotly({
    gg &lt;- ggplot(result(), aes(x = Name, y = Rate, fill = Name)) +
      theme_minimal() +
      geom_bar(stat = "identity") + 
      scale_fill_brewer(type = "qual", palette = 1)
    #gg
    p &lt;- ggplotly(gg)
    p
  })
  
  output$massPlot &lt;- renderPlotly({
    gg2 &lt;- ggplot(result(), aes(x = Name, y = Mass, fill = Name)) +
      theme_minimal() +
      geom_bar(stat = "identity") + 
      scale_fill_brewer(type = "qual", palette = 1)
    #gg2
    p2 &lt;- ggplotly(gg2)
    p2
  })
  </code></pre>
  
  <p>But when I do just normal ggplot2, the tabPanel works fine:</p>
  
  <p><code>ui.R</code></p>
  
  <pre><code>       tabsetPanel(type = "tabs", 
                     id = "tabset1",
                     tabPanel("Rate", value = "Rate", plotOutput("ratePlot")),
                     tabPanel("Mass", value = "Mass", plotOutput("massPlot"))#, plotlyOutput("massPlot"))
                    )
  </code></pre>
  
  <p><code>server.R</code></p>
  
  <pre><code>output$ratePlot &lt;- renderPlot({ #ly
    gg &lt;- ggplot(result(), aes(x = Name, y = Rate, fill = Name)) +
      theme_minimal() +
      geom_bar(stat = "identity") + 
      scale_fill_brewer(type = "qual", palette = 1)
    gg
    #p &lt;- ggplotly(gg)
    #p
  })
  
  output$massPlot &lt;- renderPlot({
    gg2 &lt;- ggplot(result(), aes(x = Name, y = Mass, fill = Name)) +
      theme_minimal() +
      geom_bar(stat = "identity") + 
      scale_fill_brewer(type = "qual", palette = 1)
    gg2
  })
  </code></pre>
  
  <p>Is there some functionality that I need to change?</p>