All Projects → RinteRface → shinyComponent

RinteRface / shinyComponent

Licence: Unknown, MIT licenses found Licenses found Unknown LICENSE MIT LICENSE.md
Single-File Components powered app

Programming Languages

javascript
184084 projects - #8 most used programming language
r
7636 projects
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to shinyComponent

skywalkR
code for Gogleva et al manuscript
Stars: ✭ 28 (+86.67%)
Mutual labels:  shiny-apps
introduction-nodejs
Introduction to NodeJS
Stars: ✭ 13 (-13.33%)
Mutual labels:  ecma
antaresViz
ANTARES Visualizations
Stars: ✭ 19 (+26.67%)
Mutual labels:  shiny-apps
ShinyTester
An R package to help debug Shiny apps during the process itself.
Stars: ✭ 29 (+93.33%)
Mutual labels:  shiny-apps
imgsvd
Shiny App for Image Compression via SVD
Stars: ✭ 22 (+46.67%)
Mutual labels:  shiny-apps
shiny crud
Example Shiny apps implementing CRUD database functionality
Stars: ✭ 88 (+486.67%)
Mutual labels:  shiny-apps
shiny.fluent
Microsoft's Fluent UI for Shiny apps
Stars: ✭ 170 (+1033.33%)
Mutual labels:  shiny-apps
PlotTwist
PlotTwist - a web app for plotting and annotating time-series data
Stars: ✭ 21 (+40%)
Mutual labels:  shiny-apps
xplorerr
Shiny apps for interactive data analysis, visualization and modeling.
Stars: ✭ 33 (+120%)
Mutual labels:  shiny-apps
conan-danmu
《名侦探柯南》B站弹幕浏览器
Stars: ✭ 37 (+146.67%)
Mutual labels:  shiny-apps
learning R
List of resources for learning R
Stars: ✭ 32 (+113.33%)
Mutual labels:  shiny-apps
workshops-setup cloud analytics machine
Tips and Tricks to setup a cloud machine for Analytics and Data Science with R, RStudio and Shiny Servers, Python and JupyterLab
Stars: ✭ 12 (-20%)
Mutual labels:  shiny-apps
shinydnd
Creating drag and drop elements in Shiny
Stars: ✭ 89 (+493.33%)
Mutual labels:  shiny-apps
machLearn
Machine learning dashboard created with R/shiny
Stars: ✭ 74 (+393.33%)
Mutual labels:  shiny-apps
wopr
An R package and Shiny application to provide API access to the WorldPop Open Population Repository (WOPR)
Stars: ✭ 28 (+86.67%)
Mutual labels:  shiny-apps
memory-hex
Hex Memory Game in Shiny
Stars: ✭ 29 (+93.33%)
Mutual labels:  shiny-apps
shiny-apps
Some of my Shiny apps for fun
Stars: ✭ 54 (+260%)
Mutual labels:  shiny-apps
MtreeRing
A tool for measuring tree-ring width
Stars: ✭ 19 (+26.67%)
Mutual labels:  shiny-apps
PlotsOfData
Shiny App for comparison of samples
Stars: ✭ 47 (+213.33%)
Mutual labels:  shiny-apps
polished example apps
Example Apps for Polished
Stars: ✭ 24 (+60%)
Mutual labels:  shiny-apps

shinyComponent

Lifecycle: experimental R-CMD-check

App powered by {golem}, webpack, Framework7 components (esm). WIP App is deployed on shinyapps.io.

Installation

You can install the released version of shinyComponent from CRAN with:

remotes::install_github("RinteRface/shinyComponent")

Proof of Concept

Interface is built with Framework 7 from JS, powered by webpack. We leverage Template components to create the app root and subroutes. On the server side, we process data from R and send them back to JS to update the components.

UI

Components may be written with JSX (supported by the framework7-loader, no need to install React!), which is more convenient than the classic template syntax. Components have either the old/new syntax so you can compare both approaches.

Main page

App component is driven by:

import ListItem from './custom-list.f7.jsx';

export default (props, {$f7, $f7ready, $on, $update }) => {
  const title = 'Hello World';
  let names = ['John', 'Vladimir', 'Timo'];

  Shiny.addCustomMessageHandler('init', function(message) {
    names = message;
    $update();
  });

  // App events callback
  $on('click', () => {
    // callback
  });

  // This method need to be used only when you use Main App Component
  // to make sure to call Framework7 APIs when app initialized.
  $f7ready(() => {
    // do stuff
    console.log('Hello');
  });

  const openAlert = () => {
    $f7.dialog.alert(title, function() {
      // ok button callback
      Shiny.setInputValue('alert_opened', false);
    });
    Shiny.setInputValue('alert_opened', true);
    Shiny.setInputValue(
      'alert',
      {
        message: 'Alert dialog was triggered!',
        title: title,
      },
      {priority: 'event'}
    );
  }

  const openPanel = () => {
    $f7.panel.open('.panel-left');
  }

  return () => (
    <div id="app">
      <div class="panel panel-left panel-init">
        <div class="block">"Hello"</div>
      </div>
      <div class="view view-main view-init safe-areas">
        <div class="page">
          <div class="navbar">
            <div class="navbar-bg"></div>
            <div class="navbar-inner">
              <div class="title">{title}</div>
            </div>
          </div>
          <div class="toolbar toolbar-bottom">
            <div class="toolbar-inner">
              <a onClick={() => openAlert()}>Open Alert</a>
              <a class="button button-fill" href="#" class="panel-open" data-panel=".panel-left">Left Panel</a>
              <a href="/extra/" data-transition="f7-cover">New Page</a>
            </div>
          </div>
          <div class="page-content">
            <ul>
              <ListItem title="Item 1" />
              <ListItem title="Item 2" />
              <ListItem title="Item 3" />
            </ul>
            <div class="list simple-list">
              <ul>
                {names.map((name) =>
                  <li>{name}</li>
                )}
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
  )
}

Below is the code a of local sub-component, being invoked in the main App template:

const ListItem = (props) => {
  return () => <li>{props.title}</li>;
}

export default ListItem

Router

This app requires a router to navigate between pages. This is done with the Framework7 builtin feature. You may pass entire app components to the router, as shown below.

import Extra from '../components/extra.f7.jsx';

export default [
  //{
  //  path: '/'
  //},
  {
    path: '/extra/',
    asyncComponent: () => Extra
  }
]

App init

Importantly, we only import Framework7 modules we need, to lighten the final bundle:

import Dialog from 'framework7/esm/components/dialog/dialog.js';
import Gauge from 'framework7/esm/components/gauge/gauge.js';
import Panel from 'framework7/esm/components/panel/panel.js';
import View from 'framework7/esm/components/view/view.js';
Framework7.use([Dialog, Gauge, Panel, View]);

App UI is initialized passing the main app component, the routes and targeting the #app element, located within the app_ui() function:

app_ui <- function(request) {
  tagList(
    # Leave this function for adding external resources
    golem_add_external_resources(),
    # Your application UI logic
    tags$body(
      div(id = "app"),
      tags$script(src = "www/index.js")
    )
  )
}

Since the JS assets have to go after the #app element in the body tag, we had to comment out the {golem} predefined script:

tags$head(
  favicon(),
  #bundle_resources(
  #  path = app_sys('app/www'),
  #  app_title = 'shinyFramework7'
  #)
  # Add here other external resources
  # for example, you can add shinyalert::useShinyalert()
  )

Whole index.js code:

import 'shiny';
// Import Framework7
import Framework7 from 'framework7';
// Import Framework7 Styles
import 'framework7/framework7-bundle.min.css';

// Install F7 Components using .use() method on class:
import Dialog from 'framework7/esm/components/dialog/dialog.js';
import Gauge from 'framework7/esm/components/gauge/gauge.js';
import Panel from 'framework7/esm/components/panel/panel.js';
import View from 'framework7/esm/components/view/view.js';
Framework7.use([Dialog, Gauge, Panel, View]);

// Import App component
import App from './components/app.f7.jsx';

// Import other routes
import routes from './modules/routes.js';

// Initialize app
var app = new Framework7({
  el: '#app',
  theme: 'ios',
  // specify main app component
  routes: routes,
  component: App
});

Server

On the server side (R):

observeEvent(TRUE, {
  session$sendCustomMessage("init", colnames(mtcars))
})

observeEvent(input$alert, {
  message(sprintf("Received from JS: %s", input$alert$message))
  message(sprintf("App title is %s", input$alert$title))
})

observe({print(input$alert_opened)})

Example

This is a basic example which shows you how to solve a common problem:

Run app

library(shinyComponent)
## basic example code
run_app()

Dev mode

library(shinyComponent)
## basic example code
packer::bundle_dev()
devtools::load_all()
run_app()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].