Reputation: 1
Just started learning R & Shiny and I'm trying to build a page that will take 2 inputs and then show the matching data. I have a dataframe with 10 columns that include "year" and "name..35" which I created select input boxes for. However, I can't get the table loaded.
The idea is, the user will first select a year, and then the name..35.. and the rows that contain both of those values will pop up as a table.
Here's my code so far (I've tried bunch of answers from here, with no luck). I would appreciate some guidance
server
output$race_standings_table = DT::renderDataTable({
standings %>%
filter(., round == standings$year)
standings %>%
filter(., race_name == standings$name..35)
})
ui
tabItem(tabName = "standings",
h2("This is the standings table page"),
fluidPage(
h1("Table test", align = "center"),
# DT::dataTableOutput("race_standings"),
fluidRow(
column(2, selectInput("round", "Select a Round:", choices = sort(unique(standings$year)), selected = NULL, multiple = FALSE)),
column(4, selectInput("race_name", "Select a Grand Prix", choices = sort(unique(standings$name..35)), selected = NULL, multiple = FALSE)),
dataTableOutput("race_standings_table"))
Upvotes: 0
Views: 48
Reputation: 86
your approach is correct, you need to create a data table UI in ui part and render data table in the server function. However in order to use input values (such as select, numeric, date etc.) you need to use input$input_id tag in the server side of shiny app.
In your case you have two input_id's: round and race_table
so your server part needs to be:
output$race_standings_table = DT::renderDataTable({
standings %>%
filter(year == input$round,
name..35 == input$race_name)
})
Have a great shiny coding :)
Upvotes: 1