Code Monkey home page Code Monkey logo

midas's Introduction

The midas Touch

Nicholas Jhirad

CRAN Status Badge CRAN Total Downloads CRAN Monthly Downloads

The midas package

This document covers version >= 0.2.0 of the package and is intended to be an
introduction to the package,

The midas package turns html code that you can find around the internet into the necessary shiny functions that would generate the equivalent shiny objects

Package Details

The package depends on:

  • xml2 parses html
  • shiny supports the shiny-object class and the tag function

Why Convert HTML?

Shiny is best when it lets us take what we see elsewhere and reproduce it in a fraction of the time attached to some great data-analysis.

I found myself with the following workflow:

# Copy an existing widget or html object
# Either from the web or from an existing function
library(shiny)
library(shinydashboard)

cat(as.character(dashboardHeader()), fill = TRUE)
## <header class="main-header">
##   <span class="logo"></span>
##   <nav class="navbar navbar-static-top" role="navigation">
##     <span style="display:none;">
##       <i class="fa fa-bars"></i>
##     </span>
##     <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
##       <span class="sr-only">Toggle navigation</span>
##     </a>
##     <div class="navbar-custom-menu">
##       <ul class="nav navbar-nav"></ul>
##     </div>
##   </nav>
## </header>
# Reproduce and Modify
logoHeader <- function(href = '#',
                       logosrc = 'logo.png',
                       loadersrc = 'loader.gif',
                       height='78%',
                       width='78%',
                       navbar = NULL) {
    tagList(
        tags$head(
            tags$script(
                "setInterval(function(){
            if ($('html').attr('class')=='shiny-busy') {
              $('div.busy').show();
              $('div.notbusy').hide();
            } else {
          $('div.busy').hide();
          $('div.notbusy').show();
        }
      },100)")
        ),
      tags$header(
          class = 'main-header',
          tags$span(
              class = 'logo',
              tags$a(href='#', class = 'logo',
                     tags$div(
                         class = 'busy',
                         tags$img(src = loadersrc,
                                  height = height,
                                  width = width)
                     ),
                     tags$div(
                         class = 'notbusy',
                         tags$img(src = logosrc,
                                  height = height,
                                  width = width)
                     )
              )
          ),
          navbar
          
      )
    )
}

But for giant pages, this involved a considerable amount of transcription of things like: <div class="example"></div> into tags$div(class="example").

I felt that this should be programmatic.

Converting HTML with midas

Let's try this with midas!

Here's some HTML I found on the internet:

# Let's Try this with midas!
library(midas)

html <- 
'<html>
<head>
<style>
#p01 {
    color: blue;
}
</style>
</head>
<body>

<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p id="p01">I am different.</p>

</body>
</html>'

print(turn_shiny(html))
## tag("html", list(tag("head", list(tag("style", list("#p01 {    color: blue;}")))), tag("body", list(tag("p", list("This is a paragraph.")), tag("p", list("This is a paragraph.")), tag("p", list(id = "p01", "I am different."))))))
## [1] "tag(\"html\", list(tag(\"head\", list(tag(\"style\", list(\"#p01 {    color: blue;}\")))), tag(\"body\", list(tag(\"p\", list(\"This is a paragraph.\")), tag(\"p\", list(\"This is a paragraph.\")), tag(\"p\", list(id = \"p01\", \"I am different.\"))))))"

midas's People

Contributors

shapenaji avatar

Stargazers

Andrew Allen Bruce avatar Matt Kumar avatar Siqi Zhang avatar  avatar Rob Gilmore avatar

Watchers

 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.