I'm new in RStudio and I am currently working on a RShiny project. The user has to give some input value: an user id, a first name, a last name or a date of birth of a client to see some specific info about this client. Based on the input, there will be a datatable of some general info about the clients that meet the input values. Because some clients can have the same first name, last name or date of birth, the user has to select the client he wants te see. Based on the selected row (of the datatable) some other info will occur. I want to filter the data based on the id of the selected row (because the id is the only thing that is unique).
I managed to do this with this code, but after some days, it suddenly didn't work anymore with the same code. The problem now is that I always see the info of the same person, regardless the row I select (for example: the datatable only shows the info of person x, also when I select person y in the datatable). Can anyone help me with this? Thank you!
This is my code:
ui.R
column(width = 3, textInput("customer_id", "Customer ID", "")),
column(width = 3, textInput("first_name", "Voornaam (hoofdletter!)", "")),
column(width = 3, textInput("last_name", "Achternaam (hoofdletter!)", "")),
column(width = 3, textInput("birth_date", "Geboortedatum (J-M-D)", "")),
fluidRow(
box(title = "Personen die voldoen aan filter", dataTableOutput("x3"), width = 12, background = "aqua")
)
fluidRow(
box(title = "Verbruik transacties", dataTableOutput(outputId = "table_use_transactions"), width = 6),
box(title = "Recharge transacties", dataTableOutput(outputId = "table_recharge_transations"), width = 6)
),
server.R
output$x3 <- renderDataTable({
table_general_info_abo <- total_customers %>%
filter(id == input$customer_id | last_name == input$last_name | first_name == input$first_name | date_of_birth == input$birth_date) %>%
select(id, first_name, last_name, date_of_birth, gender, full_address, distance_km)
DT::datatable(table_general_info_abo, selection = 'single')
})
output$table_recharge_transations <- renderDataTable({
req(input$x3_rows_selected)
table_recharge_transactions_total <- account_recharge_total %>%
filter(customer_id == table_general_info_abo[input$x3_rows_selected, 1]) %>%
select(full_date, sale_time, payment_amount, credit_bonus_amount, electronic) %>%
arrange(full_date, sale_time)
DT::datatable(table_recharge_transactions_total, options = list(lengthMenu = c(5, 10, 20), pageLength = 5), colnames = c("Date", "Time", "Amount", "Bonus", "Electronic?"))
})
output$table_use_transactions <- renderDataTable({
req(input$x3_rows_selected)
table_use_transactions_total <- account_use_total %>%
filter(customer_id == table_general_info_abo[input$x3_rows_selected, 1]) %>%
select(full_date, sale_time, machine_type, machine_number, capacity, payment_amount) %>%
arrange(full_date, sale_time)
DT::datatable(table_use_transactions_total, options = list(lengthMenu = c(5, 10, 20), pageLength = 5), colnames = c("Date", "Time", "Type", "Number", "Capacity", "Amount"))
})
Example data in the dataset 'total_customers' that you can work with is: