首页 > 解决方案 > 生成反应输入表

问题描述

我有一个反应式闪亮,它连接到 MySQL 并根据用户的输入呈现数据表。在表中mytable

A 列的值 -
B 列的值 -平局
C 列的值 - 1 到 9
D 列的值 - 0 到 150
E 列的值 - 1 或 2

这 4 个值是根据用户输入选择的。该表mytable还有其他列,例如 E 和 F,它们不依赖于用户输入。

ui <- fluidPage(fluidRow(
column(4,radioButtons("firstorsecond", "First or Second",
choices = c(1: 2),selected='1')),

column(4,radioButtons("anotherselection", "Choose won or lost",
choices = list("Won" = 1, "Lost" = 2),selected='1')),

column(4,radioButtons("result", "Match Result",
choices = list("Won" = 1, "Lost" = 2, "Tied"=3),selected='1')),


column(4,checkboxGroupInput("pos", "Position", 
choices = c(1:9),inline = TRUE)),

column(4,sliderInput("range", "Score Range", min = 0, 
    max = 150,value = c(25,75))
))
)

server <- function(input, output) 
{

 rs=dbSendQuery(mydb,"select A,B,C,D,E,F from mytable where name='abcd'")
 adv_ana=fetch(rs,n=-1)

 dataInput<-reactive({
 **code goes here**
 })
 }

dataInput<-reactive({})中,帮我弄清楚如何获取输入值并显示包含所有列的表格。

提前致谢。

标签: rshinyreactivermysql

解决方案


您可以dplyr::filter根据您的条件过滤行(未经测试,因为我没有您的数据):

datainput <- reactive{(
  your_table %>% 
    dplyr::filter(A == input$firstorsecond,
                  B == input$anotherselection,
                  C == input$result,
                  D == input$pos)
})

您可能已经适应了您的实际输入,因为我计算了 5 个输入,而在您的描述中您只提到了 4 列。


推荐阅读