Hi,
Having an issue with the renderplot function in Shiny. For some reason, Shiny does not display the graph "scatter" in the UI and I don't understand why. Everything else is displayed correctly. Please find below my code. Any reason why the plot is not displayed in the main panel? Please find the code here:
Further, but less important, I find my filtering quite repetitive as I filter for each output object. It is running well with good performance, but still, maybe there is a leaner way
You need to call the plot in order to know what should be shown. So add a line with "scatter" or "return(scatter)" as last line within the "output$scatter <- renderPlot({ })"
Here a simple example:
library(shiny)
library(dplyr)
library(magrittr)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
faithful_data = faithful %>%
mutate(waiting_mins = waiting/60)
# draw the histogram with the specified number of bins
plot = ggplot(faithful_data, aes(x = waiting_mins)) +
geom_histogram(bins = input$bins)
# you need to call the plot so it is rendered and shown!!!
plot
# or :
# return(plot)
})
}
# Run the application
shinyApp(ui = ui, server = server)