Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The dataframe with only 1 row can't display 3D bar whereas dataframe with more than one rows can display 3D bars. #3

Open
akshaybholee opened this issue Dec 17, 2020 · 0 comments

Comments

@akshaybholee
Copy link

Hello there,

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)
    })
  })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant