0

I have a sidebar where I have a inputSelect with items from my list. In the main part of Shiny, I would like to see the table changing when I change my choose in the inputSelect. I managed to do this with normal text in the header. Any one

#App
library(shiny)

ui <- fluidPage(
  headerPanel(" "),
  sidebarLayout(
    sidebarPanel(

      h4 ("Selecteer een klant uit lijst"),

      selectInput("select", 
                  label = "Kies een klant",
                  choices = list.Hikerlocaties,
                  selected = 0),
      # checkboxInput("Student", "Alleen studenten", value = TRUE),
      actionButton("zoek", "Zoek")

    ),
    mainPanel(
      textOutput("select"),
      datatable(SelectedKlant, options = list(pageLength = 20, dom = 'tip', order = list(2,'desc')), rownames = FALSE, width = 500, colnames = c('Naam', 'Klant', 'Aantal'), elementId = "results")
      )))

server <- function(input, output) {
  output$select <- renderText(input$select)
  SelectedKlant <- reactive({
    a <- subset(freq3, Klantref == input$select)
    return(a)
  })
  output$results <- renderDataTable(SelectedKlant, options = list(pageLength = 20, dom = 'tip', order = list(2,'desc')), rownames = FALSE, width = 500, colnames = c('Naam', 'Klant', 'Aantal'), elementId = "results")
} 

# Run the application 
shinyApp(ui = ui, server = server)
George
  • 73
  • 4
  • 15

1 Answers1

0
  1. The example you provide is not self-contained. You should either provide some of the data, or even better create a much simpler minimal working example

  2. Reactive expression are like functions, so you need to call SelectedKlant() to get the answer a. See here

  3. In the UI, you just need to call for DT::dataTableOutput("mytable") as in this simple example

  4. All in all, this summarizes the above:

    library(shiny)
    library(DT)
    
    ui <- basicPage(
      sidebarLayout(
        sidebarPanel(
          selectInput("select", 
                  label = "Select species",
                  choices = c('setosa','versicolor','virginica'))
    ),
    mainPanel(
      textOutput("selected_text"),
      DT::dataTableOutput("results")
        )
      )
    )
    
    server <- function(input, output) {
      output$selected_text <- renderText(input$select)
    
      SelectedKlant <- reactive({
        a <- subset(iris, Species == input$select)
        return(a)
      })
    
      output$results <- DT::renderDataTable(SelectedKlant(), options = list(pageLength = 20, dom = 'tip', order = list(2,'desc')), rownames = FALSE, width = 500, elementId = "results")
    } 
    
    # Run the application 
    shinyApp(ui = ui, server = server)
    

I hope this answers your question!

jsga
  • 156
  • 1
  • 5
  • Your work did a perfect job for me @Javier! Thanks for helping me out, and, most important, learn me something! – George Nov 05 '17 at 22:19