0

I have a reactive shiny which connects to MySQL and renders a data table upon input from the user. In table mytable,

Column A has values - Won or Lost
Column B has values - Won or Lost or Tied
Column C has values - 1 to 9
Column D has values - 0 to 150
Column E has values - 1 or 2

These 4 values are chosen based on the user input. The table mytable has other columns like E and F which do not depend on the user input.

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**
 })
 }

In dataInput<-reactive({}), help me figure out how to get the input value and display a table containing all the columns.

Thanks in advance.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
swashen
  • 13
  • 5

1 Answers1

0

You can use dplyr::filter to filter rows based on your criteria (untested as I do not have your data):

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

You may have adapt to your actual inputs, ebcasue I count there 5 inputs while in your description you mention only 4 columns.

thothal
  • 16,690
  • 3
  • 36
  • 71
  • Also how do I get the slider range values (between lower and upper) to dictate the runs showed? Because we end up having two values unlike the one value for other widgets. – swashen Mar 05 '19 at 10:34
  • the code takes your data frame and filters and return it. Check `?dplyr::filter` to learn how you can use it to look up values which are in between two values. `between` may helpyou too. – thothal Mar 05 '19 at 10:41
  • My bad. I corrected the input to match the description.This code block does not render a table but rather makes it dark grey and unresponsive. – swashen Mar 05 '19 at 10:42
  • Difficult to debug your code from the distance if we do not have your data. I guess that you may have to transform some of the variables to `numeric` to make a meaningful comparison. Please also check https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example to produce a reproducible example, which will help to get a correct answer. – thothal Mar 05 '19 at 10:49