Skip to content

[Bug]: Slices cannot be added #655

@llrs-roche

Description

@llrs-roche

What happened?

Sometimes it is not possible to add filters: The app opens but doesn't have the buttons to modify/add filters:

Image
App

library("teal.slice")
library("shiny")

datasets <- init_filtered_data(list(iris = iris, mtcars = mtcars))

ui <- fluidPage(
  fluidRow(
    column(
      width = 9,
      tabsetPanel(
        tabPanel(title = "iris", DT::DTOutput("iris_table")),
        tabPanel(title = "mtcars", DT::DTOutput("mtcars_table"))
      )
    ),
    # ui for the filter panel
    column(
      width = 3,
      # What we want to test:
      datasets$ui_filter_panel("filter_panel")
    )
  )
)

server <- function(input, output, session) {
  # this is the shiny server function for the filter panel and the datasets
  # object can now be used inside the application
  datasets$srv_filter_panel("filter_panel")
  
  # get the filtered datasets and put them inside reactives for analysis
  iris_filtered_data <- reactive(datasets$get_data(dataname = "iris", filtered = TRUE))
  mtcars_filtered_data <- reactive(datasets$get_data(dataname = "mtcars", filtered = TRUE))
  
  output$iris_table <- DT::renderDataTable(iris_filtered_data())
  output$mtcars_table <- DT::renderDataTable(mtcars_filtered_data())
}

app <- shinyApp(ui, server)
runApp(app)

If there isn't one set using set_filter_state(filter = teal_slices( <slice>)) with at least one teal_slice() the button show up.

With teal applications it is possible to add filters:

Details

library(teal)

app <- init(
  data = teal_data(iris = iris),
  modules = list(
    module(
      label = "iris histogram",
      server = function(input, output, session, data) {
        updateSelectInput(session = session,
                          inputId =  "var",
                          choices = names(data()[["iris"]])[1:4])

        output$hist <- renderPlot({
          req(input$var)
          hist(x = data()[["iris"]][[input$var]])
        })
      },
      ui = function(id) {
        ns <- NS(id)
        list(
          selectInput(inputId = ns("var"),
                      label =  "Column name",
                      choices = NULL),
          plotOutput(outputId = ns("hist"))
        )
      }
    )
  )
)

shinyApp(app$ui, app$server)

Found while testing for #653

sessionInfo()

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcore

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions