library(tidyverse)
library(RColorBrewer)
library(plotly)
# library(crosstalk)
CAT_1 <- tibble::tribble(
~Pril, ~CONF, ~ITEM, ~`PART/NO`, ~STOC, ~DIAM, ~GROS, ~LUNG, ~DINTER,
"F2722", 2029228L, 36L, "482-0278 CHG 01", 31L, 16000, 1550, 894L, 12900,
"F2722", 2021517L, 6L, "553-2140 CHG 01", 80L, 21910, 2262, 1899L, 17386,
"F2722", 2029228L, 2L, "448-8160 CHG 01", 1L, 26353, 2305, 1075L, 21743,
"F2723", 2029228L, 45L, "497-8214 CHG 00", 1L, 20320, 1981, 1142L, 16358,
"F2723", 2029228L, 43L, "496-4936 CHG 01", 53L, 32500, 2995, 875L, 26510,
"F2725", 2021517L, 2L, "578-3212 CHG 00", 62L, 17700, 1115, 1784L, 15470,
"F2730", 2021517L, 2L, "578-3212 CHG 00", 4L, 17700, 1115, 1784L, 15470,
"F2734", 2021517L, 6L, "553-2140 CHG 01", 1L, 21910, 2262, 1899L, 17386,
"F2735", 2029228L, 45L, "497-8214 CHG 00", 14L, 20320, 1981, 1142L, 16358,
"F2735", 2021517L, 6L, "553-2140 CHG 01", 54L, 21910, 2262, 1899L, 17386,
"F2735", 2029228L, 33L, "367-5119 CHG 00", 19L, 23500, 2035, 1302L, 19430,
"F2735", 2029228L, 28L, "497-8254 CHG 01", 23L, 26353, 2306, 1980L, 21741,
"F2735", 2029228L, 41L, "497-8255 CHG 00", 10L, 26353, 2306, 1806L, 21741,
"F2745", 2021517L, 2L, "578-3212 CHG 00", 6L, 17700, 1115, 1784L, 15470,
"F2745", 2029228L, 40L, "497-8249 CHG 01", 3L, 20200, 1688, 870L, 16824,
"F2745", 2029228L, 38L, "312-8827 CHG 01", 2L, 21910, 2165, 844L, 17580,
"F2745", 2029228L, 28L, "497-8254 CHG 01", 1L, 26353, 2306, 1980L, 21741,
"F2790", 2391373L, 1L, "451-9087 CHG 01", 25L, 29500, 3092, 1204L, 23316)
CAT <- CAT_1 |> mutate(PN=strtrim(`PART/NO`,8)) |>
select(PN,STOC,Pril) |>
mutate(txt=paste0("<b>",STOC,"</b>"))
nb.cols <- 45
mycolors <- colorRampPalette(brewer.pal(8, "Set2"))(nb.cols)
# df <- crosstalk::SharedData$new(CAT)$data() |>select(Pril,STOC,PN,txt)
# df
df <- CAT
df |>
plot_ly(x = ~PN, y = ~STOC, color = ~Pril,
colors = mycolors,text= ~txt, textposition ='inside',textfont = list(color = '#000002', size = 12,family ="Arial",position='midlle center' )) |>
add_bars() |>
layout(barmode = "stack") |>
layout(xaxis = list(title = "PN", tickangle = 45))
txt is with bold