1

Could someone please assist me with the below problem. I started using R shiny recently so I'm terrible at it.

I'm trying to return a value in a different column based on the choice selected in selectizeinput. e.g. I have 2 tables that look like this:

Table A

ID  Car
1   Volvo
2   Almera
3   Toyota
4   Ranger

Table B

ID  Date
1   09-Sep-09
2   23-Oct-02
3   06-Dec-95
4   18-Jan-89

in my selectizeinput my choices are the IDs. I want a function which will return the Date and Car value depending on the ID selected in the dropdown.

Your assistance will be greatly appreciated Regards, Katy

Aurèle
  • 12,545
  • 1
  • 31
  • 49
KatyLearnR
  • 17
  • 3
  • Hi KatyLearnR and welcome to SO ! Could you share the bit of code you want to improve ? Here is the link to find all the ways to share [a-great-r-reproducible-example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – cbo Oct 10 '22 at 13:31
  • I'm currently creating a dataframe using the below code: df$ID <- as.character(selectizeInput("id","",choices = unique(Table_A$ID))) and I want to create a second column in the dataframe which will return the date and car based on the value selected in the dropdown created by the above code. I've tried using : df2$Date= reactive({Table_B$Date %>% dplyr::filter(Table_B$ID==input$policynumber)}) but i get an error saying "closure is not subsettable" and "no matching records found" in the webapp table – KatyLearnR Oct 10 '22 at 13:36
  • 1
    Please update you question with your code so that anybody can jump in to help. :) It feels like you are mixing `ui` and `server` side : the 2 different parts of a shiny app. It would save you some times to do the [rstudio-tutorial](https://shiny.rstudio.com/tutorial/) (which is quite nice). – cbo Oct 10 '22 at 13:45

1 Answers1

0

Here is minimal example with the data provided and the example sample code from selectInput help page. You should first join the data, test how to fiter it then write the app :


table_cars <- read.table(text = "
ID  Car
1   Volvo
2   Almera
3   Toyota
4   Ranger", header = TRUE)

table_date <- read.table(text = "ID  Date
1   09-Sep-09
2   23-Oct-02
3   06-Dec-95
4   18-Jan-89", header = TRUE)

table_join <- merge(table_cars, table_date, by="ID")

shiny::shinyApp(
  ui = fluidPage(
    selectInput("variable", "Variable:",
                table_join$ID),
    tableOutput("data")
  ),
  server = function(input, output) {
    output$data <- renderTable({
      table_join[table_join$ID %in% input$variable, ]
    }, rownames = FALSE)
  }
)
cbo
  • 1,664
  • 1
  • 12
  • 27