I'm trying to get a simple bar chart with plotly in a Shiny app.
global.R
library(shiny)
library(ggplot2)
library(plotly)
dat <- data.frame(
time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")),
total_bill = c(14.89, 17.23)
)
ui.R
ui <- navbarPage(title = "My Shiny App",
tabPanel(title = "App",
pageWithSidebar(
headerPanel("Shiny App"),
sidebarPanel(
actionButton(inputId = "clicks",
label = "Click me")
),
mainPanel("Main Panel",
plotlyOutput("norm"),
actionButton("renorm", "Resample")
)
)
),
tabPanel(title = "Tab2",
plotOutput("unif"),
actionButton("reunif", "Resample")
),
tabPanel(title = "Tab3",
plotOutput("chisq"),
actionButton("rechisq", "Resample")
)
)
server.R
server <- function(input, output) {
output$norm <- renderPlotly({
ggplot(data=dat, aes(x=time, y=total_bill, fill=time)) +
geom_bar(stat="identity") +
guides(fill=FALSE)
})
This gives me a plot like below in the Shiny app. There are three issues I have with this.
- When I hover the plot, I want to see the bar value, its not currently being shown
- The legend is still shown even when it is set to
FALSEvia ggplot - I need to have the bars ordered with bar of largest value first - ie.
Dinnerfirst and thenLunch

