Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Labels with spaces breaks functionality #3

Open
yeelauren opened this issue Aug 23, 2018 · 3 comments
Open

Labels with spaces breaks functionality #3

yeelauren opened this issue Aug 23, 2018 · 3 comments

Comments

@yeelauren
Copy link

How can I create labels with spaces? or > 1 word?

@davesteps
Copy link
Owner

The label is NULL by default and if none is specified it uses the id of the filter, it is really the id of the filter that can't have spaces. To change the label you need to use filterInput and arguments are passed through to the relevant UI input like so:

library(shiny)
library(shinyjs)
library(dplyr)
library(shinyFilters)


# create filterset in global section of app
filterSet <- newFilterSet('FS1') %>%
  # give each filter unique id and tell it which column to filter on
  addSelectFilter('cylinders','cyl') %>%
  addSelectFilter('gears','gear') %>%
  addSliderFilter('disp',value=c(0,500)) %>%
  addSelectFilter('carb') %>%
  addCustomSliderFilter('hp',value=seq(0,500,50))


ui <- fluidPage(
  #shinyjs is required to show/hide filters
  useShinyjs(),
  sidebarLayout(
    sidebarPanel(
      # filterInput(filterSet),
      filterInput(filterSet,'cylinders',label = 'Some Name '),
      filterInput(filterSet,'gears'),
      filterInput(filterSet,'disp'),
      filterInput(filterSet,'carb'),
      filterInput(filterSet,'hp'),
      hr(),
      filterMaster(filterSet),
      filterResetButton(filterSet)
    ),
    mainPanel(
      DT::dataTableOutput("data")
    )
  )
)

server <- function(input, output,session) {
  
  # wrap data in reactive expression in case you
  # need to do something to the data before filtering
  data <- reactive(mtcars)
  
  # initialize the filter set
  filterSet <- initializeFilterSet(filterSet, data)
  
  # the output is a reactive data.frame
  output$data <- DT::renderDataTable(filterSet$output())
  
}

shinyApp(ui, server)

@yeelauren
Copy link
Author

@davesteps that works well, thank you!
Follow-up question: Is there a way to display the labels in filterMaster(filterSet) for the active filters instead of the filter id?

@davesteps
Copy link
Owner

You can't do this currently. When I can't chance I'll look into implementing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants