Coder Social home page Coder Social logo

Comments (2)

ijlyttle avatar ijlyttle commented on July 22, 2024

I think that purrr's reduce() function might be useful here.

I will try to make up an example a little later today.

from bsplus.

ijlyttle avatar ijlyttle commented on July 22, 2024

I got this to work - it turns out to be a neat exercise in purrr

library(shiny)
library(shinydashboard)
library(bsplus)
library(datasets)
library(purrr)

# create list:
#  each element contains levels for each column
#  of the data-frame that is a factor
CO2_factor_levels <- map_if(CO2_factors, is.factor, levels)

# create function:
#  given a tag (initiated with bs_accordion()), a name and a set of levels,
#  append to the tag, an accordion-panel with:
#    - a title
#    - a checkboxGroupInput with choices, identified by the name
fn_append <- function(tag, title, choices) {
  bsplus::bs_append(
    tag,
    title = title,
    content = checkboxGroupInput(
      inputId = paste0("t-", title),
      label = NULL,
      choices = choices
    )
  )
}

# Define UI for application
ui <- fluidPage(

  # starting with an initial accordon-tag, append panels according to
  # list of factor levels
  reduce2(
    names(CO2_factor_levels),
    CO2_factor_levels,
    fn_append,
    .init = bs_accordion(id = "test2")
  )

)

# Define server logic
server <- function(input, output) {

}

# Run the application
shinyApp(ui = ui, server = server)

from bsplus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.