0

I have csv file with some attributes such as age or potencial of selected football players. I would like to make a couple of different plots, which depend on users choice. For example if user choose from the first selectInput option "sprint speed" and "potencial" from second selectInput, the server function will generate plots with "sprint speed" as x value and "potencial" as y value. Here is my code (which generates a lot of errors):

**variables**
data <- read.csv("H:\\med\\lab45\\players205.csv", header = T, sep=",")

choices <- c("overall","age","potencial","preffered foot", "free kick accuracy",
         "heading accuracy", "height", "weight", "sprint speed")
tempData <- cbind(data[2],data[45],data[3],data[4],data[14],
              data[9],data[42],data[43],data[18])
names(tempData) <- c("overall","age","potencial","preffered foot", 
  "free kick accuracy","heading accuracy", "height", "weight", "sprint speed")

**UI**
ui <- fluidPage(
selectInput(inputId = "selectX", label = "select x value", choices = choices, selectize = FALSE),
  selectInput(inputId = "selectY", label = "select y value", choices = choices, selectize = FALSE),
  actionButton(label = "set new values", inputId = "submitValues"),
  plotOutput("myFirstPlot")
)

**server**
server <- function(input, output) {

  x <- reactiveValues(data = "age")

  y <- reactiveValues(data = "potencial")

  observeEvent(input$selectX,{x$data = input$selectX})
  observeEvent(input$selectY,{y$data = input$selectY})

  output$myFirstPlot <- renderPlot({
    plot(x ~ y, data=tempData)
  })
}

shinyApp(server = server, ui = ui)

and here is how it should look like:

enter image description here

David Duponchel
  • 3,959
  • 3
  • 28
  • 36

0 Answers0