Как я могу снять функцию renderPlot() в глянце с ggplot

Ниже приведен функциональный код для основного блестящего приложения, которое позволяет пользователю выбрать столбец, а затем построить ggplot::histogram() из выбранного столбца:

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(
  titlePanel("ggplot"),
  sidebarLayout(
    sidebarPanel(
      uiOutput("column_select")
    ),
    mainPanel(plotOutput("plot"))
  )

)

# Define server logic required to draw a histogram
server <- function(input, output){
  dat <- reactive({iris})
  output$column_select <- renderUI({selectInput("col", label = "column", choices = as.list(names(iris)), selected = "Sepal.Length")})
  output$plot <- renderPlot({ggplot(dat(), aes_string(x = input$col)) +
      geom_histogram()})


  p <- ggplot(dat(), aes_string(x = input$col)) +
    geom_histogram()

  renderPlot
}

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

Однако я не уверен, почему я не могу удалить функцию ggplot() из renderPlot() и все еще получить тот же результат. Я пытался:

p <- reactive({ggplot(dat(), aes_string(x = input$col)) +
    geom_histogram()})

  outputPlot <- renderPlot({p})

Но это не приводит ни к какому сюжету.

Я предполагаю, что есть простое решение, но пока оно ускользает от меня.

0 ответов

Другие вопросы по тегам