Hello I have a simple shiny app which creates a pie chart based on the input FacilityName of my dataset. I want every time that I choose a different facility my pie chart to display the share between EXT/INT (OriginId). 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().
#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<-data.frame(OriginId,FacilityName,FacId)
#ui.r
library(shinydashboard)
library(plotly)
library(data.table)
dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
#
ui <- 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 <- function(input, output,session) {
# Auftrag INT vs Ext
output$pie<-renderPlotly({
data <- dplyr::tbl_df(subset(Testdata2,Testdata2$FacilityName %in% input$variable))
ttestdata <- data.frame(data %>% group_by(OriginId) %>% mutate(Counts = n()))
p <- 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) %>%
layout(
title = paste(input$variable),
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
})
output$var<-renderUI({
selectInput("variable",
h4("Abteilung wählen:"),
choices = Testdata2 %>% distinct(FacilityName),selected = 1)
})
}

