I’m creating a simple plotly graph. The problem is when I unselect the checkboxes, that’s when the graph remains.
This is what it looks like when I check the boxes:
and this is what it looks like when I uncheck it:
Here is my code:
UI
column(width = 3,
tabBox(width = NULL,
tabPanel(h4(“Crop”),
actionLink(“selectallcrops”, “Select/Deselect All”, icon = icon(“check-square”)),
checkboxGroupInput(“crops”, “Choose Option(s):”, crops)))),
column(width = 9,
box(width = NULL, plotlyOutput(‘plot1’, height = “700px”), collapsed = F, title = “Figure”,
status = “warning”, solidHeader = T, height = “760px”))
SERVER
s.df is the dataset
output$plot1 <- renderPlotly({
validate(
need(length(input$crops) > 0, “INSTRUCTIONS: \n\n1) Select Crops Of Interest.\n2) Use ‘Farm’ tab to refine results.\n3) Hover over graph to see values.”)
)
s.df <- subset(s.df, Crop %in% input$crops)
if(input$metric == 'Acreage') {
p <- plot_ly(s.df, x = ~Farm, y = ~Acreage, color =~Crop) %>% layout(barmode = "stack", margin = list(b = 140))
}
})