shiny event_data issue related to bar-chart event

trying to render the bar-chart year (current_year) in one infobox and it's value and same thing for just previous year and it's value on another info-box as plotly_click event occurs on a bar chart, how to fetch the just previous year and its value, I have got the value of the current year and its value through event but how to get just previous year and it's value ,eventually I wanna compare them and find out the growth . looking for a reliable and efficient solution to this problem.

the following code will render the respective value as the corresponding bar on the bar chart is clicked through the plotly_click event in event_data.

#what I have done is here...
output$TotalDelivery <- renderInfoBox({
event <- event_data("plotly_click", source = "selectyear")
if (is.null(event)==F) {
infoBox(
paste("YEAR - ",event$x),
event$y,
subtitle =paste("Delivey Total")
,color = "light-blue",
icon = icon("line-chart")
)
}else
{
return(NULL)
}
})

but I want to fetch the value of the previous year automatically as the bar chart of any year is clicked(for ex. one bar is clicked and it renders its year and value in the infobox and this event also generates the year and its value for just the previous year. what should be the next step for it.

output$PublicDelivery <- renderInfoBox({
event <- event_data("plotly_click", source = "selectyear")
if (is.null(event)==F) {
infoBox(
paste("YEAR - ",as.numeric("event$x-1")),
event$y,
subtitle =paste("Delivey Total")
,color = "teal",
icon = icon("bar-chart")
)
}else
{
return(NULL)
}

when clicked on the bar chart then the value of current year and previous year render automatically in infobox respectively

})barchart cd

for now,it's rendering the value of the current year as soon as the bar-chart is clicked but how to get the value of just previous year as per the current year

You will greatly increase your chances of a helpful reply if you provide a minimal reprex, or reproducible example, that lays out the basic structure of your problem so that people can see what you've already attempted and experiment with real code. You can learn more about how to create a reprex for shiny apps at https://mastering-shiny.org/introduction.html#reprex

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.