Bar Chart Drill down

I have created bar chart but its a simple bar chart. I want to show data year-wise and then if we click on any bar of year then show the data in months of that particular year. how can i show drill-down through high chart function.

library(shiny)
MyDat <- read.csv("E:/Milind/Book1.csv")

MD1=aggregate(MyDat$Count, by=list(Years=MyDat$Year), FUN=sum) # Group_by
RS<-data.frame(Years=MD1$Years,Count=MD1$x) #Give column name
NS<-data.frame(MyDat[order(MyDat$Year),]) #Sort data
TP<-data.frame(MyDat[which(MyDat$Year==2018),])#Filter data

header <- dashboardHeader(disable = TRUE)
body <- dashboardBody(
highchartOutput("Working")
)
sidebar <- dashboardSidebar(disable = TRUE)
ui <- dashboardPage(header, sidebar, body)

server <- function(input, output, session) {
output$Working <- renderHighchart({
RS%>%
hchart('column', hcaes(x =Years, y =Count),pointWidth = 40)
})

}

shinyApp(ui, server)

Hi,

Welcome to the RStudio community!

Have you seen this vignette on the Highcharter's website? I think it explains all you need.

Hope this helps,
PJ

1 Like

Thank you so much. it's helpful for me but in that code when we pass the data to drill_down through mutate it's complicated form understanding. will you please tell me how can i pass the moths and count column to drill down..

Hi,

The mutate function is part of the dplyr package from the Tidyverse. This is an alternative way of writing the flow of your R code and provides a great set of tools for powerful data manipulations while enhancing the readability of your code.

It can indeed look a bit daunting at first (it was for me too), but it's very handy once you get the hang of it. Most functions from tidyverse have an R counterpart that you could use. In case of the mutate, it's just updating a specific column.

library(dplyr)

myData = data.frame(x = 1:10, y = LETTERS[1:10])

#Using plain R
myResult = myData
myResult[, "x"] = myResult[, "x"] + 1
myResult[myResult$x > 5, "y"] = "Z"
myResult
#>     x y
#> 1   2 A
#> 2   3 B
#> 3   4 C
#> 4   5 D
#> 5   6 Z
#> 6   7 Z
#> 7   8 Z
#> 8   9 Z
#> 9  10 Z
#> 10 11 Z

#Using mutate from dplyr
myResult = myData %>% 
  mutate(x = x + 1, y = ifelse(x > 5, "Z", x))
myResult
#>     x y
#> 1   2 2
#> 2   3 3
#> 3   4 4
#> 4   5 5
#> 5   6 Z
#> 6   7 Z
#> 7   8 Z
#> 8   9 Z
#> 9  10 Z
#> 10 11 Z

Created on 2020-07-30 by the reprex package (v0.3.0)

It's not very clear for me what your data looks like, as you have not provided me a reprex. A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here:

So if you give a a bit more detail and code on the issue, I'll try and help you further.

PJ