Giter VIP home page Giter VIP logo

shiny.histogram's Introduction

shiny.histogram

An example of shiny app that we can use flow::flow_view_shiny() on.

The minimal app is taken straight from Hadley Wickham’s “Mastering Shiny” with minor modifications.

Installation

Install with:

devtools::install_github("moodymudskipper/shiny.histogram")

Though you might be better off cloning the repo or reproducing from code below to understand the process.

Code

That’s all the package contains :

# app --------------------------------------------------------------------------

#' @export
histogramApp <- function() {
  shinyApp(ui, server)
}

# main ui function -------------------------------------------------------------

ui <- function() {
  fluidPage(
    histogramUI("hist1")
  )
}

# main server function ---------------------------------------------------------

server <- function(input, output, session) {
  histogramServer("hist1")
}

# module -----------------------------------------------------------------------

histogramUI <- function(id) {
  tagList(
    selectInput(NS(id, "var"), "Variable", choices = names(mtcars)),
    numericInput(NS(id, "bins"), "bins", value = 10, min = 1),
    plotOutput(NS(id, "hist"))
  )
}

histogramServer <- function(id) {
  moduleServer(id, function(input, output, session) {
    data <- reactive(mtcars[[input$var]])
    output$hist <- renderPlot({
      hist(data(), breaks = input$bins, main = input$var)
    }, res = 96)
  })
}

Use flow::flow_view_shiny()

library(shiny.histogram) # or devtools::load_all() if you're working in the project

# visualize whole app
flow::flow_view_shiny(histogramApp)

# focus on a component
flow::flow_view_shiny(server)

Notes

  • File organization doesn’t matter, define your function in any place in “R/”
  • ui is a function! In case your ui is an object, a “fluidPage” for instance, just wrap it into an argumentless function as I did above.
  • Shiny functions are assumed to be named after a pattern, by default we look for all functions names containing “_ui”, “_server”, “Ui”, “Server”, “UI” and “server”. The diagram will include those functions and functions which call them
  • The functions need to be in a package, if you’re working on this package you might use devtools::load_all() but don’t source or define functions manually (e.g. through the “run” button in Rstudio, or with Ctrl/Command + Enter) as it will place these functions in the global environment and we want them in a proper namespace.

shiny.histogram's People

Contributors

moodymudskipper avatar

Watchers

 avatar  avatar

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.