lineupjs / lineup_htmlwidget

HTMLWidget wrapper of LineUp for Visual Analysis of Multi-Attribute Rankings
https://lineup.js.org
Other
54 stars 9 forks source link

Adding Factor Variable with Single Level Breaks in Shiny #12

Closed JonP-16 closed 5 years ago

JonP-16 commented 5 years ago

I'm creating a Shiny app where users can filter their data and I display it in your lineup table (Thanks for making it!). Unfortunately, if the user wants to filter one of the factor variables to single level, that column and any column to the right in the table does not show up. Below I have an example where new_var is a factor with a single level and thus, the entire table doesn't show up. I think this is a bug since I didn't find anything in the help files about this.

library(shiny)
library(lineupjs)
library(dplyr)

ui <- fluidPage(
  fluidRow(
    lineupOutput("lineup1")
  )
)

server <- function(input, output) {
  output$lineup1 <- renderLineup({
    temp1 = iris %>% mutate(new_var = "test") # works because it's a character
    temp2 = iris %>% mutate(new_var = as.factor("test")) # does not work
    temp3 = iris %>% filter(Species == 'virginica') # works - don't know why it does but temp2 doesn't

    lineup(temp2, width = "100%")
  })
}

# Run the application
shinyApp(ui = ui, server = server)
sgratzl commented 5 years ago

thx for reporting. R Shiny automatically transforms arrays with just one element into a primitive value. In your case the array ["test"] was converted to "test" which is not a valid list of categories. I added a fix that is now part of the master branch