block by timelyportfolio 6002bfa21336d89ee4c4fad6cb596611

office ui fabric react in R

Full Screen

Yes, R users can use React as shown in this blog post. This example uses office-ui-fabric-react from Microsoft.

library(htmltools)
library(reactR)

fabric <- htmlDependency(
  name = "office-fabric-ui-react",
  version = "5.23.0",
  src = c(href="https://unpkg.com/office-ui-fabric-react/dist"),
  script = "office-ui-fabric-react.js",
  stylesheet = "css/fabric.min.css"
)

browsable(
  tagList(
    html_dependency_react(offline=FALSE),
    fabric,
    tags$div(id="pivot-example"),
    tags$script(HTML(babel_transform(
"
class PivotBasicExample extends React.Component {
  render() {
    return (
      <div>
        <Fabric.Pivot>
          <Fabric.PivotItem linkText='My Files'>
            <Fabric.Label>Pivot #1</Fabric.Label>
          </Fabric.PivotItem>
          <Fabric.PivotItem linkText='Recent'>
            <Fabric.Label>Pivot #2</Fabric.Label>
          </Fabric.PivotItem>
          <Fabric.PivotItem linkText='Shared with me'>
            <Fabric.Label>Pivot #3</Fabric.Label>
          </Fabric.PivotItem>
        </Fabric.Pivot>
      </div>
    );
  }
}
ReactDOM.render(<PivotBasicExample />, document.querySelector('#pivot-example'));
"
    )))
  )
)

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script src="//unpkg.com/react/umd/react.production.min.js"></script>
<script src="//unpkg.com/react-dom/umd/react-dom.production.min.js"></script>
<link href="https://unpkg.com/office-ui-fabric-react/dist/css/fabric.min.css" rel="stylesheet" />
<script src="https://unpkg.com/office-ui-fabric-react/dist/office-ui-fabric-react.js"></script>

</head>
<body style="background-color:white;">
<div id="pivot-example"></div>
<script>'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var PivotBasicExample = function (_React$Component) {
  _inherits(PivotBasicExample, _React$Component);

  function PivotBasicExample() {
    _classCallCheck(this, PivotBasicExample);

    return _possibleConstructorReturn(this, (PivotBasicExample.__proto__ || Object.getPrototypeOf(PivotBasicExample)).apply(this, arguments));
  }

  _createClass(PivotBasicExample, [{
    key: 'render',
    value: function render() {
      return React.createElement(
        'div',
        null,
        React.createElement(
          Fabric.Pivot,
          null,
          React.createElement(
            Fabric.PivotItem,
            { linkText: 'My Files' },
            React.createElement(
              Fabric.Label,
              null,
              'Pivot #1'
            )
          ),
          React.createElement(
            Fabric.PivotItem,
            { linkText: 'Recent' },
            React.createElement(
              Fabric.Label,
              null,
              'Pivot #2'
            )
          ),
          React.createElement(
            Fabric.PivotItem,
            { linkText: 'Shared with me' },
            React.createElement(
              Fabric.Label,
              null,
              'Pivot #3'
            )
          )
        )
      );
    }
  }]);

  return PivotBasicExample;
}(React.Component);

ReactDOM.render(React.createElement(PivotBasicExample, null), document.querySelector('#pivot-example'));</script>
</body>
</html>