【发布时间】:2021-03-08 19:51:19
【问题描述】:
我是 RStudio 的新手,目前正在做一个 RShiny 项目。用户必须提供一些输入值:用户 id、名字、姓氏或客户的出生日期,以查看有关此客户的某些特定信息。根据输入,将有一个关于满足输入值的客户端的一些一般信息的数据表。因为有些客户可以有相同的名字、姓氏或出生日期,所以用户必须选择他想见的客户。根据(数据表的)所选行,将出现一些其他信息。我想根据所选行的 id 过滤数据(因为 id 是唯一唯一的东西)。
我设法用这段代码做到了这一点,但几天后,它突然不再使用相同的代码了。现在的问题是,无论我选择哪一行,我总是看到同一个人的信息(例如:数据表只显示人 x 的信息,当我在数据表中选择人 y 时)。谁能帮我这个?谢谢!
这是我的代码:
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)
),
服务器.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"))
})
【问题讨论】:
-
您可能需要包含一些示例数据以让其他人看到数据结构。
-
我不知道如何包含。数据是机密的。
-
你能模拟具有相似结构的数据来重现同样的问题吗?请参阅有关可复制示例 (reprex) stackoverflow.com/help/minimal-reproducible-example 或 stackoverflow.com/questions/5963269/… 的指南
-
我添加了一些示例数据来处理
-
请提供一些可重现数据,例如
dput()。屏幕截图没有多大帮助。谢谢。
标签: r filter datatable shinydashboard