Hi all,
I'm trying to use a reactive dataframe as the data for my plots, and am running into trouble.. (one error message after another). Now, the dataframe works but when I try to plot the data, no points show up.
Can someone provide guidance on how I can use the reactive dataframe as the base of my charts/plots? Is there something wrong with the way I have specified data?
I am looking to use this same reactive dataframe for leaflet maps too..
Thanks for your time!
ui <-
fluidPage( sidebarLayout(
sidebarPanel(position = "left",width = 3, h3(strong("User Inputs", align= "left")),
numericInput("Phase_1", "Phase 1",
value = 0, min = 0, max = 5000),
numericInput("Phase_2", "Phase 2",
value = 0, min = 0, max = 12000),
numericInput("Phase_3", "Phase 3",
value = 0, min = 0, max = 20000),
mainPanel(
dataTableOutput("datatable1"), plotOutput("plot"))))
server <- function(input, output, session) {
newdata <- reactive({
Var1 <- as.numeric(input$Phase_1)
Var2 <- as.numeric(input$Phase_2)
Var3 <- as.numeric(input$Phase_3)
#total cost
dataset$Total_Cost<- Var1 + Var2 + Var3
dataset$Cost_per_person<-dataset$Total_Cost/dataset$population
dataset$Cost_per_case<-dataset$Total_Cost/dataset$cases
newdatadata<-data.frame(dataset$Area, dataset$Total_Cost, dataset$Cost_per_person, dataset$Cost_per_case).
})
output$datatable1 <- renderDataTable(newdata())
output$plot<-renderPlot({
ggplot(data=newdata(), aes(x=as.numeric(Cost_per_case), y=as.numeric(Cost_per_person))) + geom_point()+xlim(0,1000)+ylim(0,1000)
})
}
# Run the application
shinyApp(ui = ui, server = server)
Here is an example of the dataset:
Area population cases Phase_1 Phase_2 Phase_3
Area 1 99895 678 0 0 0
Area 2 10000 1002 0 0 0
Area 3 10950 602 0 0 0