生成无功输入表

时间:2019-03-05 09:51:15

标签: r shiny reactive rmysql

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

A列的值- Won Lost
B列的值- Won Lost
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({})中,帮助我弄清楚如何获取输入   值并显示包含所有列的表。

谢谢。

1 个答案:

答案 0 :(得分:0)

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

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

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