firmo23
firmo23

Reputation: 8404

Selectinput is not taking the given values and does not update the table properly

I have the dataframe below

x <- data.frame(CategoryA=c("First", "Second",
                                   "Third" ),
                CategoryB=c("First", "Second",
                                   "Third"),
                Frequency=c(10,15,5))

The shiny app which I use should take the CategoryA values as inputs and update the datatable based on this selection. The first issue is that the selectInput() takes 1,2,3 as inputs instead of "First", "Second","Third" and of course does not update the table properly.

#ui.r
pageWithSidebar(
  headerPanel('k-means '),
  sidebarPanel(
    uiOutput("inv")
  ),
  mainPanel(
    dataTableOutput("tab1")
  )
)
#server.r
library(shiny)
library(tidyverse)
library(DT)
function(input, output, session) {
  output$inv<-renderUI({
    selectInput("tow", label ="Suburb", 
                choices = c(unique(x$CategoryA)),
                multiple = T)
  })


  datasett<-reactive({
    tmp1 <- x %>% 
      filter(x[,1] == input$tow )
    tmp1
  })
  output$tab1<-renderDataTable({
    datasett()
  })
}

Upvotes: 0

Views: 20

Answers (1)

Shree
Shree

Reputation: 11140

You need stringsAsFactors = F -

x <- data.frame(CategoryA=c("First", "Second",
                                   "Third" ),
                CategoryB=c("First", "Second",
                                   "Third"),
                Frequency=c(10,15,5), stringsAsFactors = F)

also -

datasett < -reactive({
    tmp1 <- x %>% 
      filter(CategoryA %in% input$tow )
    tmp1
  })

Upvotes: 1

Related Questions