text: (window.webpackJsonp=window.webpackJsonp||[]).push([[212],{266:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return c})),n.d(t,"metadata",(function(){return p})),n.d(t,"rightToc",(function(){return s})),n.d(t,"default",(function(){return l}));var r=n(2),a=n(6),o=(n(0),n(314)),i=n(316),c={title:"Template / Data",keywords:["template"]},p={unversionedId:"examples/template-data",id:"examples/template-data",isDocsHomePage:!1,title:"Template / Data",description:"Update a template card's data periodically.",source:"@site/docs/examples/template-data.md",slug:"/examples/template-data",permalink:"/wave/docs/examples/template-data",editUrl:"https://github.com/h2oai/wave/edit/master/website/docs/examples/template-data.md",version:"current",sidebar:"someSidebar",previous:{title:"Template",permalink:"/wave/docs/examples/template"},next:{title:"Markdown",permalink:"/wave/docs/examples/markdown"}},s=[],u={rightToc:s};function l(e){var t=e.components,c=Object(a.a)(e,["components"]);return Object(o.b)("wrapper",Object(r.a)({},u,c,{components:t,mdxType:"MDXLayout"}),Object(o.b)("p",null,"Update a template card's data periodically."),Object(o.b)("div",{className:"cover",style:{backgroundImage:"url("+n(481).default+")"}}),Object(o.b)("pre",null,Object(o.b)("code",Object(r.a)({parentName:"pre"},{className:"language-py"}),"import time\nimport random\nfrom h2o_wave import site, ui\n\npage = site['/demo']\npage.drop()\n\nmenu = '''\n<ol>\n{{#each dishes}}\n<li><strong>{{name}}</strong> costs {{price}}</li>\n{{/each}}\n</ol\n'''\n\nmenu_card = page.add('template_example', ui.template_card(\n    box='1 1 2 2',\n    title='Surge-priced Menu',\n    content=menu,\n    data=dict(dishes=[\n        dict(name='Spam', price='$2.00'),\n        dict(name='Ham', price='$3.45'),\n        dict(name='Eggs', price='$1.75'),\n    ]),\n))\npage.save()\n\n\ndef rand_price():\n    return f'${random.randrange(0, 4)}.{random.randrange(10, 99)}'\n\n\ndishes = menu_card.data.dishes\nfor i in range(98, 2, -1):\n    time.sleep(1)\n    dishes[0].price = rand_price()\n    dishes[1].price = rand_price()\n    dishes[2].price = rand_price()\n    page.save()\n")),Object(o.b)("p",null,Object(o.b)("strong",{parentName:"p"},"Tags"),": \u2002",Object(o.b)("a",{href:Object(i.a)("docs/examples/tags#template")},"template")))}l.isMDXComponent=!0},314:function(e,t,n){"use strict";n.d(t,"a",(function(){return l})),n.d(t,"b",(function(){return f}));var r=n(0),a=n.n(r);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function c(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){o(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function p(e,t){if(null==e)return{};var n,r,a=function(e,t){if(null==e)return{};var n,r,a={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=a.a.createContext({}),u=function(e){var t=a.a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):c(c({},t),e)),n},l=function(e){var t=u(e.components);return a.a.createElement(s.Provider,{value:t},e.children)},d={inlineCode:"code",wrapper:function(e){var t=e.children;return a.a.createElement(a.a.Fragment,{},t)}},m=a.a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,o=e.originalType,i=e.parentName,s=p(e,["components","mdxType","originalType","parentName"]),l=u(n),m=r,f=l["".concat(i,".").concat(m)]||l[m]||d[m]||o;return n?a.a.createElement(f,c(c({ref:t},s),{},{components:n})):a.a.createElement(f,c({ref:t},s))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var o=n.length,i=new Array(o);i[0]=m;var c={};for(var p in t)hasOwnProperty.call(t,p)&&(c[p]=t[p]);c.originalType=e,c.mdxType="string"==typeof e?e:r,i[1]=c;for(var s=2;s<o;s++)i[s]=n[s];return a.a.createElement.apply(null,i)}return a.a.createElement.apply(null,n)}m.displayName="MDXCreateElement"},315:function(e,t,n){"use strict";var r=n(0),a=n(19);t.a=function(){const e=Object(r.useContext)(a.a);if(null===e)throw new Error("Docusaurus context not provided");return e}},316:function(e,t,n){"use strict";n.d(t,"b",(function(){return o})),n.d(t,"a",(function(){return i}));var r=n(315),a=n(317);function o(){const{siteConfig:{baseUrl:e="/",url:t}={}}=Object(r.a)();return{withBaseUrl:(n,r)=>function(e,t,n,{forcePrependBaseUrl:r=!1,absolute:o=!1}={}){if(!n)return n;if(n.startsWith("#"))return n;if(Object(a.b)(n))return n;if(r)return t+n;const i=n.startsWith(t)?n:t+n.replace(/^\//,"");return o?e+i:i}(t,e,n,r)}}function i(e,t={}){const{withBaseUrl:n}=o();return n(e,t)}},317:function(e,t,n){"use strict";function r(e){return!0===/^(\w*:|\/\/)/.test(e)}function a(e){return void 0!==e&&!r(e)}n.d(t,"b",(function(){return r})),n.d(t,"a",(function(){return a}))},481:function(e,t,n){"use strict";n.r(t),t.default=n.p+"assets/images/template-data-1b5f5707f248dfd5a606e722345ad2a2.png"}}]);