Я пытаюсь создать приложение Shiny для создания диаграммы рассеяния на основе набора данных Iris.Код генерирует приложение, но отображает только одну точку на графике, независимо от того, какие настройки я выберу в приложении.Вот код:
options(warn = -1)
library(shiny)
library(shinythemes)
library(dplyr)
library(readr)
library(ggplot2)
options(warn=0)
# Define UI
ui <- fluidPage(theme = shinytheme("superhero"),
titlePanel("Iris"),
sidebarLayout(
sidebarPanel(
# Select Inputs
selectInput(inputId = "y",
label = "Y-axis:",
choices = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"),
selected = "Sepal.Length"),
selectInput(inputId = "x",
label = "X-axis:",
choices = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"),
selected = "Petal.Length")
),
# Output
mainPanel(
plotOutput(outputId = "scatterplot")
)
)
)
# Define server function
server <- function(input, output) {
# Create the scatterplot object the plotOutput function is expecting
output$scatterplot <- renderPlot({
ggplot(data = iris, aes(x = input$x, y = input$y))+
geom_point(aes(color=Species, shape=Species))+
geom_smooth(method="lm")
})
}
shinyApp(ui=ui, server=server)