inst/theme_generator_app/modules/element_direction.R

element_direction_ui <- function(id) {
  ns <- NS(id)

  args <- theme_init[[id]]
  DIRECTION <- c("horizontal", "vertical")

  sidebarLayout(
    sidebarPanel = sidebarPanel(
      shinyWidgets::radioGroupButtons(
        ns("direction_type"),
        label = "Direction",
        choices = .types(),
        selected = .get_attr_type(args),
        justified = TRUE,
        width = "100%"
      ),
      selectInput(
        ns("direction"),
        label = NULL,
        choices = DIRECTION,
        selected = .set_default(args, DIRECTION[1]),
        width = "100%"
      )
    ),
    mainPanel = mainPanel(
      plotOutput(ns("plot"), height = HEIGHT) %>%
        .withSpinner()
    )
  )
}

element_direction_server <- function(id, graph) {
  moduleServer(id, function(input, output, session) {

      attrs <- list(
        "direction_type" = "direction"
      )

      mapply(.toggle_controler, names(attrs), attrs, list(input = input))

      new_theme[[id]] <- reactive({
        .assign(names(attrs), input)
        element_direction(direction = direction)
      })

      output$plot <- renderCachedPlot({
        .get_plot(graph)
      }, cacheKeyExpr = .cache_key(graph))
    }
  )
}
fanggong/themeGenerator documentation built on Dec. 20, 2021, 7:42 a.m.