How to print in R a HTML



  • I have this

    <div style="margin:auto;text-align:center">
      <strong>Types per year</strong>
      <br/>
      <div id="htmlwidget-342a290aea162ba34746" class="streamgraph html-widget" style="width:960px;height:500px;"></div>
      <div id="htmlwidget-342a290aea162ba34746-legend" style="width:960" class="streamgraph html-widget-legend"><center><label style='padding-right:5px' for='htmlwidget-342a290aea162ba34746-select'></label><select id='htmlwidget-342a290aea162ba34746-select' style='visibility:hidden;'></select></center></div>
      <script type="application/json" data-for="htmlwidget-342a290aea162ba34746">{"x":{"data":{"key":["Industrial.compound","Pesticide","Pharmaceutical","Industrial.compound","Pesticide","Pharmaceutical","Industrial.compound","Pesticide","Pharmaceutical","Industrial.compound","Pesticide","Pharmaceutical"],"value":[3.21469787709497,0.312979157894737,0.124318181818182,2.60063721925134,0.268401470588235,0.145491329479769,3.80744464705882,0.51568,0.2358755,0.51034125,0.297461538461538,0],"date":["2015-04-24","2015-04-24","2015-04-24","2016-04-24","2016-04-24","2016-04-24","2017-04-24","2017-04-24","2017-04-24","2018-04-24","2018-04-24","2018-04-24"]},"markers":null,"annotations":null,"offset":"silhouette","interactive":true,"interpolate":"cardinal","palette":"Spectral","text":"black","tooltip":"black","x_tick_interval":1,"x_tick_units":"yr","x_tick_format":"%Y","y_tick_count":0,"y_tick_format":",g","top":20,"right":40,"bottom":30,"left":50,"legend":true,"legend_label":"Type: ","fill":"brewer","label_col":"black","x_scale":"date"},"evals":[],"jsHooks":[]}</script>
    </div>
    
    

    I would like to print the plot in R but I don't know how to do it with a html.

    Can you help me?



  • Since you tagged it as Shiny, I'm going to assume you want to include raw HTML in a shiny app. In this case, you can use the HTML tag

    library(shiny)
    # add the below in your ui.R script
    
    tags$div(
    
    HTML( <your raw HTML goes here> )
    
    )
    
    
    

    See https://shiny.rstudio.com/articles/html-tags.html for more details, scrolling down to the "Raw HTML" section.



最新帖子

最新内容

  • S

    You need to create Role for system:anonymous user to watch pods on your namespace with similar to below yaml

    kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: namespace: spark # your namespace name: pod-reader # Role name will be needed for binding to user rules: - apiGroups: [""] # "" indicates the core API group resources: ["pods"] verbs: ["get", "watch", "list"]

    Then you need to create RoleBindging to bind this role to system:anonymous user with similar to below yaml

    # This role binding allows "system:anonymous" to read pods in the "spark" namespace. kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: read-pods namespace: spark # your namespace subjects: - kind: User name: system:anonymous # Name is case sensitive apiGroup: rbac.authorization.k8s.io roleRef: kind: Role #this must be Role or ClusterRole name: pod-reader # this must match the name of the Role or ClusterRole you wish to bind to apiGroup: rbac.authorization.k8s.io

    Documentation for more info about Anonymous requests

    read more
  • S
    spark version: v2.4.0 eks info: v1.10.11-eks

    after submit, got wrong message as follow:

    019-02-21 15:08:44 WARN WatchConnectionManager:185 - Exec Failure: HTTP 403, Status: 403 - pods is forbidden: User "system:anonymous" cannot watch pods in the namespace "spark" java.net.ProtocolException: Expected HTTP 101 response but was '403 Forbidden'

    Exception in thread "main" io.fabric8.kubernetes.client.KubernetesClientException: pods is forbidden: User "system:anonymous" cannot watch pods in the namespace "spark"

    read more
  • S

    I'm not sure how robust this is for a variety of reasons but it appears to work.

    #include <boost/intrusive/rbtree_algorithms.hpp> #include <cassert> #include <algorithm> #include <stack> #include <tuple> #include <iostream> namespace Foo { template <typename T> struct TNode { TNode(T i = T()) : parent(nullptr) , left(nullptr) , right(nullptr) , color(0) , value(i) , min(value) , max(value) {} TNode *parent, *left, *right; int color; int value; int min; int max; }; //Define our own rbtree_node_traits template <typename T> struct my_rbtree_node_traits { typedef TNode<T> node; typedef TNode<T> * node_ptr; typedef const TNode<T> * const_node_ptr; typedef int color; static node_ptr get_parent(const_node_ptr n) { return n->parent; } static void set_parent(node_ptr n, node_ptr parent){ n->parent = parent; } static node_ptr get_left(const_node_ptr n) { return n->left; } static void set_left(node_ptr n, node_ptr left) { n->left = left; bubbleMinMax(n); } static node_ptr get_right(const_node_ptr n) { return n->right; } static void set_right(node_ptr n, node_ptr right) { n->right = right; bubbleMinMax(n); } static color get_color(const_node_ptr n) { return n->color; } static void set_color(node_ptr n, color c) { n->color = c; } static color black() { return color(0); } static color red() { return color(1); } static void bubbleMinMax(node_ptr n) { if(n==nullptr) return; auto parent = n; typedef boost::intrusive::rbtree_algorithms<my_rbtree_node_traits<T>> algo; if(algo::is_header(parent)) { if(parent->left) parent->min = std::min(parent->left->min, parent->value); else parent->min = parent->value; if(parent->right) parent->max = std::max(parent->right->max, parent->value); else parent->max = parent->value; } else { if(parent->left) parent->min = std::min(parent->left->min, parent->value); else parent->min = parent->value; if(parent->right) parent->max = std::max(parent->right->max, parent->value); else parent->max = parent->value; bubbleMinMax(parent->parent); } } }; template <typename T> struct node_ptr_compare { bool operator()(const TNode<T> *a, const TNode<T> *b) { return a->value < b->value; } }; template <typename T> struct Traits{ typedef TNode<T> Node; typedef my_rbtree_node_traits<T> RbTraits; typedef node_ptr_compare<T> Compare; static void Print(Node const& root, int n = 0) { std::stack<std::tuple<Node const *,int,char>> stack; stack.push(std::make_tuple(&root, 0, 'R')); while(!stack.empty()) { auto item = stack.top(); auto tree = std::get<0>(item); auto depth = std::get<1>(item); auto dir = std::get<2>(item); stack.pop(); if(tree == nullptr) { std::cerr << std::string(depth * 2, ' ') << dir << "-" << std::endl; } else { std::cerr << std::string(depth * 2, ' ') << dir << " " << "value: " << tree-> value << " min: " << tree-> min << " max: " << tree->max << std::endl; stack.push(std::make_tuple(tree->right, depth + 1,'R')); stack.push(std::make_tuple(tree->left, depth + 1,'L')); } } } }; } int main() { typedef Foo::Traits<int> Traits; typedef boost::intrusive::rbtree_algorithms<Traits::RbTraits> algo; Traits::Node header, two(2), three(3); // Create an empty rbtree container: //"header" will be the header node of the tree algo::init_header(&header); for(int i = 0; i < 16 ; i++){ algo::insert_equal_upper_bound(&header, new Traits::Node(i), Traits::Compare()); } Traits::Print(*algo::root_node(&header)); }

    output is

    R value: 3 min: 0 max: 15 L value: 1 min: 0 max: 2 L value: 0 min: 0 max: 0 L- R- R value: 2 min: 2 max: 2 L- R- R value: 7 min: 4 max: 15 L value: 5 min: 4 max: 6 L value: 4 min: 4 max: 4 L- R- R value: 6 min: 6 max: 6 L- R- R value: 11 min: 8 max: 15 L value: 9 min: 8 max: 10 L value: 8 min: 8 max: 8 L- R- R value: 10 min: 10 max: 10 L- R- R value: 13 min: 12 max: 15 L value: 12 min: 12 max: 12 L- R- R value: 14 min: 14 max: 15 L- R value: 15 min: 15 max: 15 L- R-

    read more
  • S

    I've implemented myself an Interval Tree similar but not the same as in this article.. Like the article I've used a simple non self balancing binary tree. I'd like to use something like a red-black tree to keep look-ups efficient.

    However an interval tree maintains extra metadata per node such as the maximum and minimum of all intervals of all sub-trees. This means that on any tree manipulation such as insert/remove/re-balancing these values need to be recalculated.

    To simplify my concept imagine I had a tree node like below ( not the same as for an interval tree but the concept is similar )

    struct Node { double value; // the value the tree is partitioned on Node * left; Node * right; double max; // max of all values in right subtree double min; // min of all values in left subtree }

    each node contains a value and a pointer to the left and right. However the node also contains a computation of the max value of the right sub tree and a computation of the min value of the left sub tree. So I might start with an unbalanced tree like

    A(10,8,10) / B(9,8,9) / D(8,8,8)

    where the tuple represent name(value,min,max). After re balancing via whatever algorithm the tree uses I would end up with

    B(9,8,10) / \ D(8,8,8) A(10,10,10)

    However you notice the meta data is now updated. I would need some hooks in the tree code to allow me to efficiently recalculate these values for sub trees that change.

    If somebody could show how to use a boost c++ red-black tree or another self balancing tree to do the above simple structure then I am sure I could extended it to my more complex interval tree code.

    An attempt has been made to do this with boost::intrusive but it will not really work.

    http://coliru.stacked-crooked.com/a/1ec5d00968532035

    This is because the available hooks provide no guarantees on the state of the tree when the call is made, thus trying to navigate the tree at this point is equivalent to a race condition in multithreaded code. Anything might happen.

    #include <boost/intrusive/rbtree_algorithms.hpp> #include <cassert> #include <algorithm> #include <stack> #include <tuple> #include <iostream> namespace Foo { template <typename T> struct TNode { TNode(T i = T()) : left(nullptr) , right(nullptr) , color(0) , value(i) , min(value) , max(value) {} TNode *parent, *left, *right; int color; int value; int min; int max; }; //Define our own rbtree_node_traits template <typename T> struct my_rbtree_node_traits { typedef TNode<T> node; typedef TNode<T> * node_ptr; typedef const TNode<T> * const_node_ptr; typedef int color; static node_ptr get_parent(const_node_ptr n) { return n->parent; } static void set_parent(node_ptr n, node_ptr parent){ n->parent = parent; } static node_ptr get_left(const_node_ptr n) { return n->left; } static void set_left(node_ptr n, node_ptr left) { n->left = left; bubbleMinMax(n); } static node_ptr get_right(const_node_ptr n) { return n->right; } static void set_right(node_ptr n, node_ptr right) { n->right = right; bubbleMinMax(n); } static color get_color(const_node_ptr n) { return n->color; } static void set_color(node_ptr n, color c) { n->color = c; } static color black() { return color(0); } static color red() { return color(1); } static void bubbleMinMax(node_ptr n) { if(n==nullptr) return; typedef boost::intrusive::rbtree_algorithms<my_rbtree_node_traits<T>> algo; auto parent = n; while(parent!=nullptr&&!algo::is_header(parent)) { if(parent->left) parent->min = std::min(parent->left->min, parent->value); else parent->min = parent->value; if(parent->right) parent->max = std::max(parent->right->max, parent->value); else parent->max = parent->value; if(parent->parent == parent) break; parent = parent->parent; } } }; template <typename T> struct node_ptr_compare { bool operator()(const TNode<T> *a, const TNode<T> *b) { return a->value < b->value; } }; template <typename T> struct Traits{ typedef TNode<T> Node; typedef my_rbtree_node_traits<T> RbTraits; typedef node_ptr_compare<T> Compare; static void Print(Node const& root, int n = 0) { std::stack<std::tuple<Node const *,int,char>> stack; stack.push(std::make_tuple(&root, 0, 'R')); while(!stack.empty()) { auto item = stack.top(); auto tree = std::get<0>(item); auto depth = std::get<1>(item); auto dir = std::get<2>(item); stack.pop(); if(tree == nullptr) { std::cerr << std::string(depth * 2, ' ') << dir << "-" << std::endl; } else { std::cerr << std::string(depth * 2, ' ') << dir << " " << "value: " << tree-> value << " min: " << tree-> min << " max: " << tree->max << std::endl; stack.push(std::make_tuple(tree->right, depth + 1,'R')); stack.push(std::make_tuple(tree->left, depth + 1,'L')); } } } }; } int main() { typedef Foo::Traits<int> Traits; typedef boost::intrusive::rbtree_algorithms<Traits::RbTraits> algo; Traits::Node header, two(2), three(3); // Create an empty rbtree container: //"header" will be the header node of the tree algo::init_header(&header); for(int i = 0; i < 8 ; i++){ algo::insert_equal_upper_bound(&header, new Traits::Node(i), Traits::Compare()); } Traits::Print(*algo::root_node(&header)); }

    and the output is

    L value: 1 min: 0 max: 7 L value: 0 min: 0 max: 0 L- R- R value: 2 min: 2 max: 2 L- R- R value: 5 min: 4 max: 7 L value: 4 min: 4 max: 4 L- R- R value: 6 min: 6 max: 7 L- R value: 7 min: 7 max: 7 L- R-

    which is clearly wrong. The first left node has a max of 7 in its subtree but there are no nodes there with a value of 7.

    read more
  • S

    recently I started using Navigation Component Architecture, now there's a problem I have. in previous fragment transactions we could set tag while transacting to another fragment, how can we do that while using Navigation Component Architecture.

    read more

推荐阅读