Giter Site home page Giter Site logo

bar's Introduction

bar

Htmlwidgets for proportions-chart, built with {packer}.

Lifecycle: experimental R-CMD-check

Installation

You can install the released version of {bar} from GitHub with:

remotes::install_github("dreamRs/bar")

Example

Installed capacities to produce energy in France (source eco2mix):

Code:

library(bar)

# Installed capacities by sectors in France 
# source: https://www.rte-france.com/eco2mix/les-chiffres-cles-de-lelectricite
installed <-data.frame(
  sector = c("Bioenergies", "Fuel oil", "Coal", "Solar",  "Gas", "Wind", "Hydraulic", "Nuclear"),
  value  = c(        2119L,      2892L,  2978L,   9613L, 12196L, 16727L,      25483L,    62250L)
)

# Visualize data
bar(
  data = installed,
  colors = list(
    "Bioenergies" = "#156956",
    "Fuel oil" = "#80549f",
    "Coal" = "#a68832",
    "Solar" = "#d66b0d",
    "Gas" = "#f20809",
    "Wind" = "#72cbb7",
    "Hydraulic" = "#2672b0",
    "Nuclear" = "#e4a701"
  )
)

Development

Install {packer} (see packer's documentation).

Install nodes modules with:

packer::npm_install()

Modify srcjs/widgets/bar.js, then run:

packer::bundle()

Re-install package and try bar() function.

bar's People

Contributors

johncoene avatar pvictor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bar's Issues

Bar does not update but append svg when changing the input

Let me start off by saying that I really love the simple elegance of these bar charts!

However, I'm having some trouble with dynamic inputs because the bar is not updated/replaced when changing the input but instead a second bar appears below the first one (and so on).

Below is a simple reprex:

library(shiny)
library(tidyverse)

ui <- fluidPage(
  fluidPage(
    selectInput("Input", label="choose", choices=c("mpg", "cyl")),
    fluidRow(barOutput("bar")
    )
  )
)

server <- function(input,output,session)({
  
  output$bar <- renderBar({
    
    dt <- mtcars %>% 
      add_rownames(var = "rowname") %>% 
      select(rowname, input$Input)
    cols = map(rev(colorRampPalette(c("#FFFFFF", "#000000"))(nrow(dt))), as.character())
    names(cols) <- dt$rowname

    bar(data = dt, colors = cols)
    
  })
})

shinyApp(ui = ui, server = server)

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.