I should create in my shiny app this conditions: In the UI setup add a selectInput field: the first argument is the name (how to access the selection in the server setup, we will call this "species"), the second argument is the label (appears on the app), and the third argument should list the choices: here we want to choose between the three different species (can you obtain the three choices from the data directly?).
I receive this error in my code: I receive this error: Error in match.arg(position) : 'arg' must be NULL or a character vector
CODE:
library(shiny)
library(palmerpenguins)
library(ggplot2)
# Define UI for application that draws a plot
ui <- fluidPage(
# Application title
titlePanel("Penguins"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput(inputId = "VarX",
label = "Select X-axis Variable",
choices = list("flipper_length_mm","species","island",
"bill_length_mm","bill_depth_mm","body_mass_g",
"sex","year")),
selectInput(inputId = "VarY",
label = "Select Y-axis Variable",
choices = list("flipper_length_mm","species","island",
"bill_length_mm","bill_depth_mm","body_mass_g",
"sex","year")),
selectInput(
inputId = "varColor",
label = "Color",
choices = c("species"),
selected = "species")),
selectInput(
inputId = "species",
label = "select species",
choices = list("adelie","gentoo","chinstrap")),
# Show a plot
mainPanel(
plotOutput("scatter")
)
)
)
#Define server logic required to draw a scatter
server <- function(input, output) {
pengu <- reactive({ggplot(penguins,
aes(y = bill_depth_mm, x = bill_length_mm))+
geom_point(aes(color = .data[[input$species]]))})
output$scatter <- renderPlot({
pengu()
})
}
# Run the application
shinyApp(ui = ui, server = server)