title: Toggle between plotly bar chart to plotly column chart by using an actionButton
body: <p>I have the <code>shiny</code> app below which displays a bar chart with <code>Country</code> in <code>yaxis</code> and <code>Value</code> in <code>xaxis</code>. Im trying to change it to: <code>Country</code> as <code>xaxis</code> and <code>Value</code> as <code>yaxis</code> by clicking on <code>Exchange</code> <code>actionButton()</code>. I should toggle between those two bu clicking on <code>Exchange</code></p>
  <pre><code>library(shiny)
  library(DT)
  
  Country&lt;-c(&quot;EU&quot;,&quot;CHE&quot;,&quot;ITA&quot;)
  Value&lt;-c(3,2,1)
  dat&lt;-data.frame(Country,Value)
  
  ui &lt;- fluidPage(
    sidebarLayout(
      sidebarPanel(
        
        
        actionButton(&quot;exc&quot;,
                     &quot;Exchange&quot;)
      ),
      mainPanel(
        uiOutput(outputId = &quot;plot&quot;)
        
      )
    )
  )
  server &lt;- function(input, output) {
    
    excplot &lt;- reactiveVal(TRUE)
    
    observeEvent(input$exc, {
      excPlot(!excplot())
    })
    
    
    output[[&quot;bar1&quot;]]&lt;-renderPlotly({
          fig1 &lt;- plot_ly(dat, x = ~Value, y = ~Country,
                          type = 'bar', orientation = 'h',
                          hovertemplate = paste('%{y}', '&lt;br&gt;Value: %{x}&lt;br&gt;'),
                          marker = list(color = 'green')
          ) 
          fig1 &lt;- fig1 %&gt;% layout(
            
            yaxis = list(title=&quot;&quot;,showgrid = FALSE, showline = FALSE, showticklabels = TRUE, domain= c(0, 0.85)),
            xaxis = list(title=&quot;&quot;,zeroline = FALSE, showline = FALSE, showticklabels = FALSE, showgrid = FALSE)) 
          fig1 &lt;- fig1 %&gt;% add_annotations(xref = 'x1', yref = 'y',
                                           x =  dat$Value* 1.1 + 0.5,  y = dat$Country,
                                           text = paste(round(dat$Value, 2), '%'),
                                           font = list(family = 'Arial', size = 12, color = 'black'),
                                           showarrow = FALSE)
          fig1 
        })
    
    output$plot &lt;- renderUI({
      plotlyOutput(&quot;bar1&quot;)
    })
  }
  shinyApp(ui = ui, server = server)
  </code></pre>