Hi,
I have a barchart and I want to write the screen selected column name/value. I have read a sample in here with plot. I tried everything but I can not do. Is there anyway to do this with barchart? I read many articles but could not find solution. Thanks.
server.R
#max 10 country by deaths count
output$deathsTotalBarChart <- renderPlot({
#we get input parameter from the screen
prm_Continent=input$Continent
prm_Continent=ifelse(prm_Continent=="Global","ALL",ifelse(prm_Continent=="Asia","AS",ifelse(prm_Continent=="Europe","EU",ifelse(prm_Continent=="Africa","AF","AM"))))
if(prm_Continent!="ALL"){
Result=Result[Result$Continent==prm_Continent,]
}
Result=subset(Result, select=(c("geoId","Country","deathsTotal","casesTotal","Continent")))
Result=Result[order(-Result[,"deathsTotal"]), ]
Result=head(Result, 10)
ggplot(Result, aes(x=Result$Country, y=Result$deathsTotal, fill=Country)) +
geom_bar(position = "dodge",stat="identity")+
geom_text(aes(label=Result$deathsTotal),position=position_dodge(width=1),vjust=1.6, color="black", size=4)+
theme(axis.text.x = element_text(colour = "black", size = 12, angle = 45, hjust = 0.5, vjust = 0.5))+
xlab("Country") + ylab("Total Deaths")
})
Print the name of the x value
output$x_value <- renderText({
if (is.null(input$plot1_click$x)) return("Could not get values")
else {
lvls <- levels(Result$Country)
name <- lvls[round(input$plot1_click$x)]
HTML("You've selected ", name, "
",
"
Here are the first 10 rows that ",
"match that category:")
}
})
ui.R
fluidRow(
shinydashboard::box(
title = "Top 10 Countries with the Highest Death Count", status = "primary",solidHeader = TRUE, plotOutput("deathsTotalBarChart", click = "plot1_click", height = 300), width = 12
)),
fluidRow(
shinydashboard::box(
title = "", status = "primary",htmlOutput("x_value"), width = 12
)),