Hello guys,
I am trying to produce 3d barchart with highcharter with z-axis label and x-axis label showing. But when my dataframe has only one row the chart doesnot display the bars. If the dataframe consist of more than one row it displays properly.
I want to be able to display 1 row from the dataframe also in the chart.
Below is a reproducible example:
library(shiny)
library(highcharter)
shinyApp(
ui <- fluidPage(
fluidRow(
highchartOutput('chart')
)
),
server <- function(input, output, session) {
df <- data.frame(
Z1 = c(1, 2, 1, 4),
Z2 = c(2, 3, 2, 7),
Z3 = c(6, 3, 7, 4),
Z4 = c(3, 4, 1, 5)
)
df <- df[-(1:3),] #reduced dataframe to 1 row
dta <- lapply(seq(ncol(df)), function(x) {
list(
name = colnames(df)[x],
data = df[, x]
)
})
output$chart <- renderHighchart({
highchart() %>%
hc_chart(
type = "column",
options3d = list(
enabled = TRUE,
beta = 20,
alpha = 30,
depth = 400,
viewDistance = 10
)
) %>%
hc_xAxis(categories = row.names(df[1:nrow(df)-1,])) %>%
hc_zAxis(
min = 0,
max = 3,
categories = colnames(df)
) %>%
hc_plotOptions(
series = list(
depth = 100,
grouping = FALSE,
groupZpadding = 10
)
) %>%
hc_add_series_list(dta)
})
})