I'm trying to build a donut plot in my shiny app that uses plotly, similar to this one from another question). However' my plot never appears. I've researched other answer (such as this one, this one, and this one), but they don't get me closer to my answer.
What am I doing wrong?
library(shiny)
library(dplyr)
library(plotly)
my_colors <- c("#00A3AD", "#FF8200", "#753BBD")
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
),
mainPanel(
fluidRow(
plotlyOutput("count_by_person")
))
))
server <- function(input, output) {
output$count_by_person <- renderPlotly({
data <- tibble(name = c("Justin", "Corey", "Sibley"),
n = c(1, 3, 6),
prop = c(.1, .3, .6))
plot_ly(data, aes(x = 2, y = prop, fill = name)) +
geom_bar(stat = "identity", color = "white") +
coord_polar(theta = "y", start = 0)+
geom_text(aes(y = lab.ypos, label = paste0("n = ", n, ", \n", prop, "%")), color = "white")+
scale_fill_manual(values = my_colors) +
theme_void() +
xlim(.5, 2.5)
})
}
shinyApp(ui, server)