title: Use ggplot and ggplotly instead of plot_ly to create a pie chart
body: <p>Hello I have a simple shiny app which creates a pie chart based on the input <code>FacilityName</code> of my dataset. I want every time that I choose a different facility my pie chart to display the share between EXT/INT (<code>OriginId</code>). Also every piece should display the share and the number of "kunden".Unfortunately plot_ly() does not seem to work properly for me so I would to use ggplot() instead and then convert it to plotly with ggplotly(). </p>
  
  <p><a href="https://i.stack.imgur.com/jOp5g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jOp5g.png" alt="enter image description here"></a></p>
  
  <pre><code>#data
  OriginId=c("INT","EXT","INT","INT","EXT","INT","EXT","INT")
  FacilityName=c("t1","t1","t2","t2","t1","t3","t4","t5")
  FacId=c("t1","t1","t2","t2","t1","t3","t4","t5")
  Testdata2&lt;-data.frame(OriginId,FacilityName,FacId)
  
  #ui.r
  library(shinydashboard)
  library(plotly)
  library(data.table)
  
  dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody()
  )
  #
  ui &lt;- dashboardPage(skin = "black",
                      dashboardHeader(title = img(src="Logo1.jpg", height = 50, align = "left")
  
                      ),
  
                      ## Sidebar content
                      dashboardSidebar(
                        sidebarMenu(
                          menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
  
                        )
                      ),
  
                      ## Body content
                      dashboardBody(
                        tabItems(
  
                          # Dashboard tab
                          tabItem(tabName = "dashboard",
                                  fluidRow(
                                    box(title = "Verhältnis interner / externer Aufträge", status = "primary", solidHeader = TRUE,
                                        plotlyOutput("pie",height = 250)),
                                    uiOutput("var")
  
                                  )
  
                          )
  
  
  
                        )
                      )
  )
  #server.r
  server &lt;- function(input, output,session) {
  
    # Auftrag INT vs Ext
    output$pie&lt;-renderPlotly({
  
      data &lt;- dplyr::tbl_df(subset(Testdata2,Testdata2$FacilityName %in% input$variable))
      ttestdata &lt;- data.frame(data %&gt;% group_by(OriginId) %&gt;% mutate(Counts = n())) 
      p &lt;- plot_ly(data, labels=data$OriginId, values = table(data$OriginId), type = 'pie',
                   textposition = 'inside',
                   insidetextfont = list(color = '#FFFFFF'),
                   hoverinfo = 'text',
                   text = ~paste(ttestdata$Counts, ' Kunden'),
                   marker = list(
                     line = list(color = '#FFFFFF', width = 1)),
                   showlegend = FALSE) %&gt;%
        layout(
          title = paste(input$variable),
          xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
          yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
  
    })
  
  
  
    output$var&lt;-renderUI({
      selectInput("variable",
                  h4("Abteilung wählen:"),
                  choices = Testdata2 %&gt;% distinct(FacilityName),selected = 1)
    })
  
  }
  </code></pre>