0

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)
  • 1
    The parentheses after `sidebarPanel` don't close correctly, they should close after the last `selectInput`. However, I'm also not sure what you want to select with the species `selectInput`, because there are no different columns for the species, just one which you could filter – starja Jan 05 '23 at 12:03
  • Does this answer your question? [How to connect user input with gganimate graph in R shiny?](https://stackoverflow.com/questions/71810703/how-to-connect-user-input-with-gganimate-graph-in-r-shiny) – Limey Jan 05 '23 at 12:06
  • Thanks, I do not have the error anymore now, still have to figure out how to solve the taks. I forgot to add a second part of the task: In the server setup update your plotting code: we will make the plot such that the selected species gets highlighted. Instead of mapping species to color we will check if the species is equal to the selected one (this information is stored in input$species) instead. You might want to change the color scale here: not selected should be gray, selected in color. – Francesco Jan 05 '23 at 13:13

0 Answers0