Edit: Thanks for the help, there were multiple issues with my code but the main issue was that I was missing an Observe statement, the following solved the problem:
get_ddf <- reactive({
filter(poskick, Name == input$player)
})
observe({
updateSelectInput(session, 'fixture', choices =levels(droplevels(get_ddf()$Event)) )
})
I want my Shiny app to have two selectInput dropdowns, the first one selecting a name and the second selcting from the events a person took part in, based on a subset created by the first input. sample data:
PLID Name x_coord y_coord x_coord_end y_coord_end action Event
7046 Sample Name1 35 37 34 25 4 23/07/11
7046 Sample Name1 21 11 0 0 4 23/07/11
7046 Sample Name1 49 60 56 8 4 23/07/11
7046 Sample Name1 46 56 72 34 4 23/07/11
7046 Sample Name1 58 49 24 58 4 23/07/11
7046 Sample Name1 87 57 42 52 4 23/07/11
7046 Sample Name1 14 58 18 37 4 23/07/11
7140 Sample Name2 38 14 11 11 4 23/07/11
7140 Sample Name2 11 11 11 11 4 23/07/11
7140 Sample Name2 56 8 56 8 4 23/07/11
my code UI:
library(shiny)
library(ggplot2)
poskick<-read.csv('poskicks.csv')
shinyUI(pageWithSidebar(
headerPanel("position map"),
sidebarPanel(
selectInput('player', 'Player', choices= attributes(poskick$Name)),
selectInput('fixture', 'Match', choices= attributes(firstsub()$Fixtu))
),
mainPanel(
plotOutput('plot')
)
))
Server Code:
library(shiny)
library(ggplot2)
poskick<-read.csv('poskicks.csv')
shinyServer(function(input, output) {
firstsub <- reactive({
subset(poskick, poskick$Name %in% input$player)
})
secondsub <- reactive({
subset(poskick, poskick$Fixtu %in% input$fixture & poskick$Name %in% input$player )
})
output$plot <- renderPlot({
p <- ggplot(data = secondsub()) + geom_segment(aes(x = x_coord, y = y_coord, xend = x_coord_end, yend = y_coord_end))
print(p) }, height=700)
})
Any suggestions are appreciated, Thank You.
updateSelectInput()function allows you to update the options based on logic on the server. See shiny.rstudio.com/gallery/update-input-demo.html for some example code. - GregF