Home > database >  How to show ggplot from external function in shiny R application?
How to show ggplot from external function in shiny R application?

Time:10-24

I need to create shiny app which will create a plot basing on dropdown menu choise. The whole computation part is pretty complicated and so is the plot – I created a function which is returning ggplot and I just wanted to show it in the app. My idea looks as follows:

library(shiny)
source('Analysis/function_external.R')
list_names = c('a', 'b', 'c')
ui <- fluidPage(
    selectInput("data", "Select data to plot", choices = list_names)
)

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

  observe({function_external(input$data)})

}

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

It is making function run every time I change the input, but it does not show anything. I would really appreciate if you can point me into good direction.

CodePudding user response:

output$my_complicated_plot <- renderPlot({ function_external(input$data) }) Solved the issue.

  • Related