Thanks for fixing the formatting! 
A few things were going wrong here (and I hope I've correctly understood what the code is aiming for — let me know if not!):
- The
df() reactive used as the data argument to ggplot() wasn't actually created anywhere
- Instead, a data frame named
df was created inside the renderTable(), but this won't be available to anything outside of renderTable()
- The
x aesthetic for the plot is set to factor(input$Company), but...
- there is no
input$Company (you have an input$company, instead — note capitalization!)
- assuming the code is meant to be plotting the data frame defined inside
renderTable(), then the only variables in that data frame are Company and Expenditures (there is no variable named after whatever the user has entered in input$company).
A couple minor notes:
- You don't need to load both
ggplot2 and tidyverse — ggplot2 gets loaded automatically when you load tidyverse
- You don't need to use
factor() on the x variable in your plot, since the data frame was made with data.frame() which converts character variables into factors by default oops, Company is created as a character variable at the gather() step, but it still doesn't matter since geom_col() treats whatever you give it for x as categorical data.
- The
server() code includes the line output$company <- renderText({ input$company }), but there isn't actually any output called "company". The sum() reactive also isn't used anywhere. I removed these two definitions to simplify, but you should put them back if they're important for your real code.
Does this version do what you're hoping for? If not, can you explain more about what you want the plot to look like?
library(shiny)
library(shinydashboard)
library(DT)
library(tidyverse)
header <- dashboardHeader(title = "Customer Acquisition compared to Customer Retention")
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Marketing", tabName = "Marketing", icon = icon("dashboard"))
))
body <- dashboardBody(
tabItems(
tabItem(tabName = "Marketing",
h3("Annual Marketing Costs"),
fluidRow(
box(title = "Direct Costs", solidHeader = TRUE, status = "primary",
textInput("company", "Company", "Company Name"),
sliderInput("wd", "Web Design", min=0, max =1000, 3000, round=TRUE),
sliderInput("wh", "Web Hosting", min=0, max =1000,500, round=TRUE),
box(title = "Customer Acquisition vs Customer Retention? ", solidHeader = TRUE, status = "primary",
plotOutput("plot"),
tableOutput("data")))))))
ui <- dashboardPage(skin="blue",
header,
sidebar,
body
)
server <- function(input, output) {
df <- reactive({
data.frame(Company = input$company, WebDesign = input$wd, WebHosting = input$wh) %>%
gather("Company", "WebDesign:WebHosting") %>%
rename("Expenditure" = "WebDesign:WebHosting")
})
output$data <- renderTable({
df() %>% set_names(input$company, names(df())[2])
})
output$plot <- renderPlot({
ggplot(df(), aes(Company, Expenditure)) +
geom_col() +
labs(x = input$company)
})
}
# Run the application
shinyApp(ui = ui, server = server)