Appsilon / reactable.extras

Extra features for reactable package
https://appsilon.github.io/reactable.extras/
38 stars 4 forks source link

Add number_extra() for numeric inputs in reactable #26

Closed Johan-rosa closed 10 months ago

Johan-rosa commented 1 year ago

Have you read the Contributing Guidelines?

Issue #25

Changes description

  1. number_extra function and its js wrapper numberExtras were added

How to test

Run this example and play with the numbers

library(shiny)
library(reactable)
library(reactable.extras)

string_list <- function(values) {
  paste0(
    "{", paste0(names(values), " : ", unlist(values), collapse = ", "), "}"
  )}

ui <- fluidPage(
  reactable_extras_dependency(),
  reactableOutput("react"),
  textOutput("number_text"),
  textOutput("text")
)

server <- function(input, output, session) {
  output$react <- renderReactable({
    tibble::tibble(
      name = c("Portfolio 1", "Portfolio 2", "Portfolio 3"),
      expected_return = c(0.0687, 0.060, 0.050) * 100,
      expected_volatility = c(0.1575, 0.140, 0.120) * 100
    ) |>
      reactable(
        columns = list(
          name = colDef(cell = text_extra("text")),
          expected_return = colDef(cell = number_extra("number", class = "number-extra"))
        )
      )
  })
  output$text <- renderText({
    req(input$text)
    values <- input$text
    paste0(
      "Text: ",
      string_list(values)
    )
  })

  output$number_text <- renderText({
    req(input$number)
    values <- input$number
    paste0(
      "Text: ",
      string_list(values)
    )
  })
}

shinyApp(ui, server)
prasan2421 commented 4 months ago

I cannot see number_extra() working yet. Is this function still yet to be released?