Coder Social home page Coder Social logo

wildart / stipple.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from genieframework/stipple.jl

0.0 0.0 0.0 1.2 MB

The reactive UI library for interactive data applications with pure Julia.

License: MIT License

JavaScript 81.71% Julia 15.27% CSS 3.03%

stipple.jl's Introduction

Genie Logo

Stipple.jl

    Reactive Data Apps in Pure Julia

Docs current status Website Tests Stipple Downloads Tweet

Stipple is a reactive UI library for building interactive data applications in pure Julia. It uses Genie.jl (on the server side) and Vue.js (on the client). Stipple uses a high performance MVVM architecture, which automatically synchronizes the state two-way (server -> client and client -> server) sending only JSON data over the wire. The Stipple package provides the fundamental communication layer, extending Genie's HTML API with a reactive component.


The Stipple ecosystem also includes:

  • StippleUI.jl - the UI library for Stipple.jl, providing access to 30+ reactive UI elements (including forms, lists, tables, as well as layout).
  • StippleCharts.jl - the charts library for Stipple.jl, providing access to a growing collection of reactive charts.
  • StipplePlotly.jl - alternative plotting library for Stipple.jl which uses Plotly.
  • StipplePlotlyExport.jl - add-on for StipplePlotly.jl to allow server side generation and exporting of plots.
  • StippleLatex.jl - support for (reactive) Latex content.

Installation

Stipple can be added from the GitHub repo, via Pkg:

pkg> add Stipple

Examples

Downloadable demos repo available at: https://github.com/GenieFramework/StippleDemos

Example 1


Add Genie and Stipple first:

pkg> add Stipple
pkg> add Genie

Now we can run the following code at the Julia REPL:

using Stipple

@reactive mutable struct Name <: ReactiveModel
  name::R{String} = "World!"
end

function ui(model)
  page( model, class="container", [
      h1([
        "Hello "
        span("", @text(:name))
      ])

      p([
        "What is your name? "
        input("", placeholder="Type your name", @bind(:name))
      ])
    ]
  )
end

route("/") do
  model = Name |> init
  html(ui(model), context = @__MODULE__)
end

up() # or `up(open_browser = true)` to automatically open a browser window/tab when launching the app

This will start a web app on port 8000 and we'll be able to access it in the browser at http://localhost:8000

Once the page is loaded, we'll be able to interact with the data and see how it's synced.

We can update the name value from Julia, and see it reflected on the page, at the REPL:

julia> model.name[] = "Adrian" # updating the property in Julia will update the values on the front

On the webpage, we can change the name in the input field and confirm that it has been updated in Julia:

julia> model.name[] # will have the same value as what you have inputted on the web page

You can see a quick video demo here: https://www.dropbox.com/s/50t5bqd2zk4ehxo/basic_stipple_3.mp4?dl=0

The Stipple presentation from JuliaCon 2020 is available here (8 minutes): https://www.dropbox.com/s/6atyctgomsqwjki/stipple_exported.mp4?dl=0

Example 2

This snippet illustrates how to build a UI where the button triggers a computation (function call) on the server side, using the input provided by the user, and outputting the result of the computation back to the user.

using Genie.Renderer.Html, Stipple, StippleUI

@reactive mutable struct Model <: ReactiveModel
  process::R{Bool} = false
  output::R{String} = ""
  input::R{String} = ""
end

function handlers(model)
  on(model.process) do _
    if (model.process[])
      model.output[] = model.input[] |> reverse
      model.process[] = false
    end
  end

  model
end

function ui(model)
  page(model, class="container", [
      p([
        "Input "
        input("", @bind(:input), @on("keyup.enter", "process = true"))
      ])

      p([
        button("Action!", @click("process = true"))
      ])

      p([
        "Output: "
        span("", @text(:output))
      ])
    ]
  )
end

route("/") do
  model = Model |> init |> handlers
  html(ui(model), context = @__MODULE__)
end

isrunning(:webserver) || up()

Choosing the transport layer: WebSockets or HTTP

By default Stipple will attempt to use WebSockets for real time data sync between backend and frontend. However, in some cases WebSockets support might not be available on the host. In this case, Stipple can be switched to use regular HTTP for data sync, using frontend polling with AJAX (1s polling interval by default). Stipple can be configured to use AJAX/HTTP by passing the transport param to the init() method, ex:

model = Stipple.init(Name(), transport = Genie.WebThreads)

The current available options for transport are Genie.WebChannels (default, using WebSockets) and Genie.WebThreads (using HTTP/AJAX).

Given that polling generates quite a number of extra requests, it can be desirable to disable automatic logging of requests. This can be done using Genie.config.log_requests = false.

Support for WebThreads and request logging disabling has been introduced in Genie v1.14 and Stipple v0.8.

First example changed to use WebThreads

using Genie.Renderer.Html, Stipple

Genie.config.log_requests = false

@reactive mutable struct Name <: ReactiveModel
  name::R{String} = "World!"
end

function ui(model)
  page(model, class="container",
    [
      h1([
        "Hello "
        span("", @text(:name))
      ])

      p([
        "What is your name? "
        input("", placeholder="Type your name", @bind(:name))
      ])
    ]
  )
end

route("/") do
  model = Stipple.init(Name(), transport = Genie.WebThreads)
  html(ui(model), context = @__MODULE__)
end

isrunning(:webserver) || up()

Demos

German Credits visualisation dashboard

The full application is available at: https://github.com/GenieFramework/Stipple-Demo-GermanCredits

Iris Flowers dataset k-Means clustering dashboard

The full application is available at: https://github.com/GenieFramework/Stipple-Demo-IrisClustering

stipple.jl's People

Contributors

abhimanyuaryan avatar essenciary avatar hhaensel avatar jeremiedb avatar roflmaostc avatar yakir12 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.