I'm trying to wrap my head around shiny to start developing interactive charts and maybe eventually design a dashboard using bootsrap and shiny.
I'm trying to adapt the telephones by region example to understand the calls to buttons and such.
Telephones by regionWhat I'm trying to do is to have two buttons on the left: the first one selects a state, the second one a month.
The bar graph to be shown is always the state and country together for comparison. The call with the button for state is something I dont fully understand.
My data can be in one table or multiple tables, it doesnt matter. Here's a fictirioius example
Geography characteristics month1 month2
Country Urate 7 7.5
Country EmpRate 67 68
Country PartRate 61 62
State1 Urate 8 7.5
State1 EmpRate 65 66
State1 PartRate 60 59
State2 Urate 10 9
Now, the r code to generate the graphs is not the issue. I work with R but shiny is something new to me.
Any insights would be greatly appreciated. Below I have included my current code (not properly working bcode in development).
# Define the overall UI
shinyUI(
# Use a fluid Bootstrap layout
fluidPage(
# Give the page a title
titlePanel("LFA by State"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
selectInput("Geography", "State:",
choices=colnames(StateLFA)),
hr(),
helpText("Data from Census 2011")
),
# Create a spot for the barplot
mainPanel(
plotOutput("LFAPlot")
)
)
)
)
Server:
StateLFA <- read.csv("table.csv")
# Define a server for the Shiny app
shinyServer(function(input, output) {
# Fill in the spot we created for a plot
output$LFAPlot <- renderPlot({
# Render a barplot
ggplot(ProvLFA, aes(x=characteristics, y=value, fill=Geography)) +
geom_bar(position = "dodge", stat="identity") +
theme_classic() +
theme(axis.text.x = element_text(vjust=0.5, size=15),
axis.text.y = element_text(vjust=0.5, size=15)) +
theme(panel.border = element_blank()) +
theme(legend.text=element_text(size=16)) +
theme(legend.position="bottom") +
theme(axis.title.x=element_text(size=15)) +
theme(plot.background=element_rect(fill = "transparent",
colour = NA)) +
scale_fill_brewer(palette="Paired") +
ylab("") + xlab("") +
guides(fill=guide_legend(title=NULL)) +
ggtitle("\n") +
geom_text(aes(label=Percent), vjust=-0.5, position=position_dodge(width=0.9))
#Percent label can be white and inside the bar
#geom_text(aes(label=Percent), vjust=1, colour="white",
#position=position_dodge(width=0.9))
})
})