R Shiny plot appearing in popup window intead of in the app itself

Here is a example of my setup. Assuming there is a plotOutput("example") in the UI function, this will go in the server function:

output$example <- renderPlot({  testPlot() })

testPlot <- function() { 
     ggplot(data = mpg, mapping = aes(x = displ, y = hwy, color= drv)) + 
          geom_smooth(mapping = aes(linetype = drv), method = 'loess') +
          geom_point()
}

this example code itself works fine, the plot appears on the app page. But when I run my code (which is structured similarly, it has a renderPlot which makes a call to a function that returns a ggplot), the plot shows up in a separate window.

What could be causing the plot to open in a separate popup window rather than render in the app? No ggplot options would cause this as far as I'm aware.

Hej,
i think its most likely your UI.
Just post a minimal shinyapp code ... like this:


#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(

    # Application title
    titlePanel("example app"),

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
        sidebarPanel(
            p('example Sidebar')
        ),

        # Show a plot of the generated distribution
        mainPanel(
           plotOutput("example")
        )
    )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

    
    testPlot <- function() { 
        ggplot(data = mpg, mapping = aes(x = displ, y = hwy, color= drv)) + 
            geom_smooth(mapping = aes(linetype = drv), method = 'loess') +
            geom_point()
    }
    output$example <- renderPlot({  testPlot() })
}

# Run the application 
shinyApp(ui = ui, server = server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.