From 6e06bd2b1125681fa8ef805066cb455cec404b49 Mon Sep 17 00:00:00 2001 From: Brian Caffo Date: Wed, 15 Jan 2014 12:29:02 -0500 Subject: [PATCH] working on shiny apps --- 07_RegressionModels/scratch.Rmd | 17 ++ 07_RegressionModels/scratch.html | 96 ++++++++ 07_RegressionModels/scratch.md | 17 ++ .../shiny/fig/simplestApp.png | Bin 0 -> 41518 bytes 09_DevelopingDataProducts/shiny/index.Rmd | 214 +++++++++--------- 09_DevelopingDataProducts/shiny/index.html | 188 --------------- 09_DevelopingDataProducts/shiny/index.md | 191 +++++++++------- .../shiny/simplestApp/server.R | 5 + .../shiny/simplestApp/ui.R | 10 + .../shiny/testApp/server.R | 24 +- 09_DevelopingDataProducts/shiny/testApp/ui.R | 35 +-- 11 files changed, 401 insertions(+), 396 deletions(-) create mode 100644 07_RegressionModels/scratch.Rmd create mode 100644 07_RegressionModels/scratch.html create mode 100644 07_RegressionModels/scratch.md create mode 100644 09_DevelopingDataProducts/shiny/fig/simplestApp.png create mode 100644 09_DevelopingDataProducts/shiny/simplestApp/server.R create mode 100644 09_DevelopingDataProducts/shiny/simplestApp/ui.R diff --git a/07_RegressionModels/scratch.Rmd b/07_RegressionModels/scratch.Rmd new file mode 100644 index 0000000..cbb133a --- /dev/null +++ b/07_RegressionModels/scratch.Rmd @@ -0,0 +1,17 @@ +--- +title : Scratch work +subtitle : +author : Brian Caffo, Jeff Leek and Roger Peng +job : Johns Hopkins Bloomberg School of Public Health +logo : bloomberg_shield.png +framework : io2012 # {io2012, html5slides, shower, dzslides, ...} +highlighter : highlight.js # {highlight.js, prettify, highlight} +hitheme : tomorrow # +url: + lib: ../../libraries + assets: ../../assets +widgets : [mathjax] # {mathjax, quiz, bootstrap} +mode : selfcontained # {standalone, draft} +--- + +--- \ No newline at end of file diff --git a/07_RegressionModels/scratch.html b/07_RegressionModels/scratch.html new file mode 100644 index 0000000..58ea88a --- /dev/null +++ b/07_RegressionModels/scratch.html @@ -0,0 +1,96 @@ + + + + Scratch work + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Scratch work

+

+

Brian Caffo, Jeff Leek and Roger Peng
Johns Hopkins Bloomberg School of Public Health

+
+
+ + + +
+ +
+
+ +
+ +
+ + +
+ +
+
+ +
+ +
+ + +
+ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/07_RegressionModels/scratch.md b/07_RegressionModels/scratch.md new file mode 100644 index 0000000..6c89e72 --- /dev/null +++ b/07_RegressionModels/scratch.md @@ -0,0 +1,17 @@ +--- +title : Scratch work +subtitle : +author : Brian Caffo, Jeff Leek and Roger Peng +job : Johns Hopkins Bloomberg School of Public Health +logo : bloomberg_shield.png +framework : io2012 # {io2012, html5slides, shower, dzslides, ...} +highlighter : highlight.js # {highlight.js, prettify, highlight} +hitheme : tomorrow # +url: + lib: ../../libraries + assets: ../../assets +widgets : [mathjax] # {mathjax, quiz, bootstrap} +mode : selfcontained # {standalone, draft} +--- + +--- diff --git a/09_DevelopingDataProducts/shiny/fig/simplestApp.png b/09_DevelopingDataProducts/shiny/fig/simplestApp.png new file mode 100644 index 0000000000000000000000000000000000000000..24ed98d16aa99611592515cb1ab1e7353a546988 GIT binary patch literal 41518 zcmeHPdpy)>+yBi0BZX3Hi$U2`tFTK^<5X?wgr29;0Yj^j#K>XB*-R(9ootUn#Ap>Q zq0$(PVLDJb7a1`#Mj8@xa2_)b?@vst!u$O9?)&-t{u?tt_kG>p`?|i@_qy(T=J(xp zHuL5znF9d8yzSe5`8NP45CH)38YK_D6QA*X6#(b}+ke@(HxS#!wz%ueykRQhWj}M> zrdcXqtcTo>GrmnjdAA;O-92ZKylFbNZf;(U2|jwqU0=1e4)fzmZ=+7YSM5D8cUSaQ z*Sg-9x)^NLDR|wY+vO)p|+7DI_{gFhkw%=F7_9VNHBn24gMPyR2;^*(| zyCVS@9EnoZu_jLcLeEfi8VKyMFq!=^)J;VcaSd|Tp->gSSOezKTjS+t9}CH-pWc?w zW*%Fn10-$NwLLTYb8uJB8CE45$#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`XHp&WhOz8LXbjU z`ZcLTf&YKZrQ>HtbYWO_;c!p+rO$`CKgx{`P>ZiyjSW@vz+;pw&6c00ONS_bxdAO8 zVu%;(PVQ;+%uF2CIb0Ea|Mk{?;?)9phzhZIs4bzVMBU}u zewQ#x=pe0mjUl~n0YNq+2}Z&dkK~4eXI4DJh@qW9ote~|fBt$$M!{1v&;4iy2f;nM z7Cin@i4bo-sC6{2u)0e7^HAX=b(hcwh2XgnPr*t|5;2#_&O@e-=ITCvz=PS(lba?3 zOr1^@>~2K9oI53xeVHvjJ!@?TW|yj>yBDTOyHh|p3_cZC0mw|9^2rn<-Y--I+Pf~M zPc=f8Vg9xPGHYTRAhagE8uBeD5~orIL=X@`e37Xjf`AADB8aIP5F!YOAifpskd~js z1X2(XK|lln5yZC$Km_qc>*k-*gVq&kqqU%NL;+S#K(neHY@Z?vja|CZp2% z(XwxEeNK6Yv4#s2y_|AybP|m(-ldRF2nvC5~1KPqAeEifir`|=GGSTFdK1yap+|OS){I?5)fC9e`3jqa( zJPL_|LXQY>6iA*Bnd?AV&zcy!quon(7XXq9NE9R$AgM4evmvPfNd>SlfusT?6~-%N zNGgE8zy@^^Ab9}B0@O)>FJK=J^R2ar6Nxa$HPE_DW&{b;aFci8< zJ<&*k?n*&-rJ%b~Q1{>y0+2j_}`y(JX@0L$P0%f`K*?y`PvZB2avUEcV|T;7=IGfak$EeUpgtR~IR@yUGfr=)=G NTkL+x+T?ore*g`%ZeIWZ literal 0 HcmV?d00001 diff --git a/09_DevelopingDataProducts/shiny/index.Rmd b/09_DevelopingDataProducts/shiny/index.Rmd index 54bfb56..2c344bc 100644 --- a/09_DevelopingDataProducts/shiny/index.Rmd +++ b/09_DevelopingDataProducts/shiny/index.Rmd @@ -1,103 +1,111 @@ ---- -title : Shiny -subtitle : Data Products -author : Brian Caffo, Jeff Leek, Roger Peng -job : Johns Hopkins Bloomberg School of Public Health -logo : bloomberg_shield.png -framework : io2012 # {io2012, html5slides, shower, dzslides, ...} -highlighter : highlight.js # {highlight.js, prettify, highlight} -hitheme : tomorrow # -url: - lib: ../../libraries - assets: ../../assets -widgets : [mathjax] # {mathjax, quiz, bootstrap} -mode : selfcontained # {standalone, draft} ---- - -## What is Shiny? - -- Shiny is a platform for creating interactive R programs embeded into a web page. -- Suppose that you create a prediction algorith, with shiny you can *very easily* create web input form that calls R and thus your prediction algorithm and displays the results. -- Using Shiny, the time to create simple, yet powerful, web-based interactive data products in R is minimized. - - However, it lacks the flexibility of full featured (and more complex) solutions. -- Shiny is made by the fine folks at R Studio. - ---- -## Some mild prerequisites -- Shiny doesn't really require it, but as with all web programming, a little knowledge of html, css and js is very helpful - - html gives a web page structure and sectioning as well as markup instructions - - css gives the style - - js for interactivity -- There are too many tutorials online to count for getting basic proficiency in these topics to count. -- Shiny uses [bootstrap](http://getbootstrap.com/) (no relation to the statistics bootstrap) style, which (to me) seems to look nice and renders well on mobile platforms - ---- -## What else is out there? -- Full solutions requiring real knowledge of web client/server programming -- [OpenCPU](https://public.opencpu.org/) by Jerome Ooms, a really neat project providing an API to call - ---- -## Context -- You created a novel prediction algorithm to predict risk for developing - diabetes. - - You're hoping patients and caregivers will be able to enter their data and, if needed, take preventative measures. -- You want to create a web site so that users can input the relevant predictors and obtain their prediction. -- Your prediction algorithm (ok, so you're not going to be saving the world with this one) - - (link for a real prediction score)[http://www.ncbi.nlm.nih.gov/pubmed/12610029] -```{r} -diabetesRisk <- function(glucose){ - runif(1) -} -``` - - ---- -## Getting started -- Great tutorial at -(http://rstudio.github.io/shiny/tutorial/)[http://rstudio.github.io/shiny/tutorial/] -- Basically, this lecture is walking through that tutorial offering some of our insights -- Note, some of the proposed interactive plotting uses of Shiny could be handled by the very simple `manipulate` function (rstudio manipulate)[http://www.rstudio.com/ide/docs/advanced/manipulate] -- Also, `rCharts` is will be covered in a different lecture. - -``` -install.packages("shiny") -``` - -```{r} -library(shiny) -``` - ---- -## A Shiny project -- A shiny project contains two parts - - One named ui.R (for user interface) controls how it looks. - - One named server.R that controls what it does. - ---- -## -``` -library(shiny) -shinyUI(pageWithSidebar( - headerPanel("Hello Shiny!"), - sidebarPanel( - sliderInput("obs", - "Number of observations:", - min = 1, - max = 1000, - value = 500) - ), - mainPanel( - plotOutput("distPlot") - ) -)) -``` - ---- -## - - - - - - - +--- +title : Shiny +subtitle : Data Products +author : Brian Caffo, Jeff Leek, Roger Peng +job : Johns Hopkins Bloomberg School of Public Health +logo : bloomberg_shield.png +framework : io2012 # {io2012, html5slides, shower, dzslides, ...} +highlighter : highlight.js # {highlight.js, prettify, highlight} +hitheme : tomorrow # +url: +# lib: ../../libraries + assets: ../../assets +widgets : [mathjax] # {mathjax, quiz, bootstrap} +mode : selfcontained # {standalone, draft} +--- + +## What is Shiny? + +- Shiny is a platform for creating interactive R programs embeded into a web page. +- Suppose that you create a prediction algorith, with shiny you can *very easily* create web input form that calls R and thus your prediction algorithm and displays the results. +- Using Shiny, the time to create simple, yet powerful, web-based interactive data products in R is minimized. + - However, it lacks the flexibility of full featured (and more complex) solutions. +- Shiny is made by the fine folks at R Studio. + +--- +## Some mild prerequisites +- Shiny doesn't really require it, but as with all web programming, a little knowledge of html, css and js is very helpful + - html gives a web page structure and sectioning as well as markup instructions + - css gives the style + - js for interactivity +- There are too many tutorials online to count for getting basic proficiency in these topics to count. +- Shiny uses [bootstrap](http://getbootstrap.com/) (no relation to the statistics bootstrap) style, which (to me) seems to look nice and renders well on mobile platforms + +--- +## What else is out there? +- Full solutions requiring real knowledge of web client/server programming +- [OpenCPU](https://public.opencpu.org/) by Jerome Ooms, a really neat project providing an API to call + +--- +## Context +- You created a novel prediction algorithm to predict risk for developing + diabetes. + - You're hoping patients and caregivers will be able to enter their data and, if needed, take preventative measures. +- You want to create a web site so that users can input the relevant predictors and obtain their prediction. +- Your prediction algorithm (ok, so you're not going to be saving the world with this one) + - (link for a real prediction score)[http://www.ncbi.nlm.nih.gov/pubmed/12610029] +```{r} +diabetesRisk <- function(glucose){ + runif(1) +} +``` + + +--- +## Getting started +- Make sure you have the latest release of R installed +- If on windows, make sure that you have Rtools installed +- `install.packages("shiny")` +- `libray(shiny)` +- Great tutorial at +[http://rstudio.github.io/shiny/tutorial/](http://rstudio.github.io/shiny/tutorial/) +- Basically, this lecture is walking through that tutorial offering some of our insights +- Note, some of the proposed interactive plotting uses of Shiny could be handled by the very simple `manipulate` function [rstudio manipulate](http://www.rstudio.com/ide/docs/advanced/manipulate) +- Also, `rCharts` is will be covered in a different lecture. + +--- +## A Shiny project +- A shiny project is a directory containing at least two parts + - One named ui.R (for user interface) controls how it looks. + - One named server.R that controls what it does. + +--- +## ui.R +``` +library(shiny) +shinyUI(pageWithSidebar( + headerPanel("Data science FTW!"), + sidebarPanel( + h3('Sidebar text') + ), + mainPanel( + h3('Main Panel text') + ) +)) +``` + +--- +## server.r +``` +library(shiny) +shinyServer( + function(input, output) { + } +) +``` + +--- +## To run it +- In R, change to the directories with these files and type `runApp()` +- or put the path to the directory as an argument +- It should open an browser window with the app running + +--- +![simplestApp](fig/simplestApp.png "First Shiny app") + + + + + + + diff --git a/09_DevelopingDataProducts/shiny/index.html b/09_DevelopingDataProducts/shiny/index.html index 6dba9fe..e69de29 100644 --- a/09_DevelopingDataProducts/shiny/index.html +++ b/09_DevelopingDataProducts/shiny/index.html @@ -1,188 +0,0 @@ - - - - Shiny - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

Shiny

-

Data Products

-

Brian Caffo, Jeff Leek, Roger Peng
Johns Hopkins Bloomberg School of Public Health

-
-
- - - -
-

What is Shiny?

-
-
-
    -
  • Shiny is a platform for creating interactive R programs embeded into a web page.
  • -
  • Suppose that you create a prediction algorith, with shiny you can very easily create web input form that calls R and thus your prediction algorithm and displays the results.
  • -
  • Using Shiny, the time to create simple, yet powerful, web-based interactive data products in R is minimized. - -
      -
    • However, it lacks the flexibility of full featured (and more complex) solutions.
    • -
  • -
  • Shiny is made by the fine folks at R Studio.
  • -
- -
- -
- - -
-

Some mild prerequisites

-
-
-
    -
  • Shiny doesn't really require it, but as with all web programming, a little knowledge of html, css and js is very helpful - -
      -
    • html gives a web page structure and sectioning as well as markup instructions
    • -
    • css gives the style
    • -
    • js for interactivity
    • -
  • -
  • There are too many tutorials online to count for getting basic proficiency in these topics to count.
  • -
  • Shiny uses bootstrap (no relation to the statistics bootstrap) style, which (to me) seems to look nice and renders well on mobile platforms
  • -
- -
- -
- - -
-

What else is out there?

-
-
-
    -
  • Full solutions requiring real knowledge of web client/server programming
  • -
  • OpenCPU by Jerome Ooms, a really neat project providing an API to call
  • -
- -
- -
- - -
-

Context

-
-
-
    -
  • You created a novel prediction algorithm to predict risk for developing -diabetes. - -
      -
    • You're hoping patients and caregivers will be able to enter their data and, if needed, take preventative measures.
    • -
  • -
  • You want to create a web site so that users can input the relevant predictors and obtain their prediction.
  • -
  • Your prediction algorithm (ok, so you're not going to be saving the world with this one) - -
  • -
- -
diabetesRisk <- function(age, bmi, ahtm, glucose) {
-    runif(1)
-}
-
- -
- -
- - -
-

Getting started

-
- - -
- - -
- - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/09_DevelopingDataProducts/shiny/index.md b/09_DevelopingDataProducts/shiny/index.md index 105925c..0bc0c04 100644 --- a/09_DevelopingDataProducts/shiny/index.md +++ b/09_DevelopingDataProducts/shiny/index.md @@ -1,78 +1,113 @@ ---- -title : Shiny -subtitle : Data Products -author : Brian Caffo, Jeff Leek, Roger Peng -job : Johns Hopkins Bloomberg School of Public Health -logo : bloomberg_shield.png -framework : io2012 # {io2012, html5slides, shower, dzslides, ...} -highlighter : highlight.js # {highlight.js, prettify, highlight} -hitheme : tomorrow # -url: - lib: ../../libraries - assets: ../../assets -widgets : [mathjax] # {mathjax, quiz, bootstrap} -mode : selfcontained # {standalone, draft} ---- - -## What is Shiny? - -- Shiny is a platform for creating interactive R programs embeded into a web page. -- Suppose that you create a prediction algorith, with shiny you can *very easily* create web input form that calls R and thus your prediction algorithm and displays the results. -- Using Shiny, the time to create simple, yet powerful, web-based interactive data products in R is minimized. - - However, it lacks the flexibility of full featured (and more complex) solutions. -- Shiny is made by the fine folks at R Studio. - ---- -## Some mild prerequisites -- Shiny doesn't really require it, but as with all web programming, a little knowledge of html, css and js is very helpful - - html gives a web page structure and sectioning as well as markup instructions - - css gives the style - - js for interactivity -- There are too many tutorials online to count for getting basic proficiency in these topics to count. -- Shiny uses [bootstrap](http://getbootstrap.com/) (no relation to the statistics bootstrap) style, which (to me) seems to look nice and renders well on mobile platforms - ---- -## What else is out there? -- Full solutions requiring real knowledge of web client/server programming -- [OpenCPU](https://public.opencpu.org/) by Jerome Ooms, a really neat project providing an API to call - ---- -## Context -- You created a novel prediction algorithm to predict risk for developing - diabetes. - - You're hoping patients and caregivers will be able to enter their data and, if needed, take preventative measures. -- You want to create a web site so that users can input the relevant predictors and obtain their prediction. -- Your prediction algorithm (ok, so you're not going to be saving the world with this one) - - (link for a real prediction score)[http://www.ncbi.nlm.nih.gov/pubmed/12610029] - -```r -diabetesRisk <- function(age, bmi, ahtm, glucose) { - runif(1) -} -``` - - - ---- -## Getting started -- Great tutorial at -(http://rstudio.github.io/shiny/tutorial/)[http://rstudio.github.io/shiny/tutorial/] -- Basically, this lecture is walking through that tutorial offering some of our insights - -``` -install.packages("shiny") -``` - - -```r -library(shiny) -``` - - - - - - - - - +--- +title : Shiny +subtitle : Data Products +author : Brian Caffo, Jeff Leek, Roger Peng +job : Johns Hopkins Bloomberg School of Public Health +logo : bloomberg_shield.png +framework : io2012 # {io2012, html5slides, shower, dzslides, ...} +highlighter : highlight.js # {highlight.js, prettify, highlight} +hitheme : tomorrow # +url: +# lib: ../../libraries + assets: ../../assets +widgets : [mathjax] # {mathjax, quiz, bootstrap} +mode : selfcontained # {standalone, draft} +--- + +## What is Shiny? + +- Shiny is a platform for creating interactive R programs embeded into a web page. +- Suppose that you create a prediction algorith, with shiny you can *very easily* create web input form that calls R and thus your prediction algorithm and displays the results. +- Using Shiny, the time to create simple, yet powerful, web-based interactive data products in R is minimized. + - However, it lacks the flexibility of full featured (and more complex) solutions. +- Shiny is made by the fine folks at R Studio. + +--- +## Some mild prerequisites +- Shiny doesn't really require it, but as with all web programming, a little knowledge of html, css and js is very helpful + - html gives a web page structure and sectioning as well as markup instructions + - css gives the style + - js for interactivity +- There are too many tutorials online to count for getting basic proficiency in these topics to count. +- Shiny uses [bootstrap](http://getbootstrap.com/) (no relation to the statistics bootstrap) style, which (to me) seems to look nice and renders well on mobile platforms + +--- +## What else is out there? +- Full solutions requiring real knowledge of web client/server programming +- [OpenCPU](https://public.opencpu.org/) by Jerome Ooms, a really neat project providing an API to call + +--- +## Context +- You created a novel prediction algorithm to predict risk for developing + diabetes. + - You're hoping patients and caregivers will be able to enter their data and, if needed, take preventative measures. +- You want to create a web site so that users can input the relevant predictors and obtain their prediction. +- Your prediction algorithm (ok, so you're not going to be saving the world with this one) + - (link for a real prediction score)[http://www.ncbi.nlm.nih.gov/pubmed/12610029] + +```r +diabetesRisk <- function(glucose) { + runif(1) +} +``` + + + +--- +## Getting started +- Make sure you have the latest release of R installed +- If on windows, make sure that you have Rtools installed +- `install.packages("shiny")` +- `libray(shiny)` +- Great tutorial at +[http://rstudio.github.io/shiny/tutorial/](http://rstudio.github.io/shiny/tutorial/) +- Basically, this lecture is walking through that tutorial offering some of our insights +- Note, some of the proposed interactive plotting uses of Shiny could be handled by the very simple `manipulate` function [rstudio manipulate](http://www.rstudio.com/ide/docs/advanced/manipulate) +- Also, `rCharts` is will be covered in a different lecture. + +--- +## A Shiny project +- A shiny project is a directory containing at least two parts + - One named ui.R (for user interface) controls how it looks. + - One named server.R that controls what it does. + +--- +## ui.R +``` +library(shiny) +shinyUI(pageWithSidebar( + headerPanel("Data science FTW!"), + sidebarPanel( + h3('Sidebar text') + ), + mainPanel( + h3('Main Panel text') + ) +)) +``` + +--- +## server.r +``` +library(shiny) +shinyServer( + function(input, output) { + } +) +``` + +--- +## To run it +- In R, change to the directories with these files and type `runApp()` +- or put the path to the directory as an argument +- It should open an browser window with the app running + +--- +![simplestApp](fig/simplestApp.png "First Shiny app") + + + + + + + diff --git a/09_DevelopingDataProducts/shiny/simplestApp/server.R b/09_DevelopingDataProducts/shiny/simplestApp/server.R new file mode 100644 index 0000000..ef1ee00 --- /dev/null +++ b/09_DevelopingDataProducts/shiny/simplestApp/server.R @@ -0,0 +1,5 @@ +library(shiny) +shinyServer( + function(input, output) { + } +) diff --git a/09_DevelopingDataProducts/shiny/simplestApp/ui.R b/09_DevelopingDataProducts/shiny/simplestApp/ui.R new file mode 100644 index 0000000..4b84559 --- /dev/null +++ b/09_DevelopingDataProducts/shiny/simplestApp/ui.R @@ -0,0 +1,10 @@ +library(shiny) +shinyUI(pageWithSidebar( + headerPanel("Hello Shiny!"), + sidebarPanel( + h3('Sidebar text') + ), + mainPanel( + h3('Main Panel text') + ) +)) diff --git a/09_DevelopingDataProducts/shiny/testApp/server.R b/09_DevelopingDataProducts/shiny/testApp/server.R index 7e70448..d380873 100644 --- a/09_DevelopingDataProducts/shiny/testApp/server.R +++ b/09_DevelopingDataProducts/shiny/testApp/server.R @@ -1,14 +1,10 @@ -library(shiny) - -#diabetesRisk <- function(glucose) runif(1) - -shinyServer(function(input, output) { - -}) - -#shinyServer(function(input, output) { -# output$prediction <- renderPrint({ - #cat(diabetesRisk(input$glucose)) -# cat(1) -# }) -#}) +library(shiny) + +diabetesRisk <- function(glucose) glucose / 200 + +shinyServer( + function(input, output) { + output$inputValue <- renderPrint({input$glucose}) + output$prediction <- renderPrint({diabetesRisk(input$glucose)}) + } +) diff --git a/09_DevelopingDataProducts/shiny/testApp/ui.R b/09_DevelopingDataProducts/shiny/testApp/ui.R index ecd9722..c611219 100644 --- a/09_DevelopingDataProducts/shiny/testApp/ui.R +++ b/09_DevelopingDataProducts/shiny/testApp/ui.R @@ -1,13 +1,22 @@ -library(shiny) - -shinyUI(pageWithSidebar( - - headerPanel("Glucose prediction"), - - sidebarPanel(), - - mainPanel() -)) - -# h3('Results of prediction'), -# verbatimTextOutput("prediction") +library(shiny) + +# Define UI for dataset viewer application +shinyUI( + pageWithSidebar( + # Application title + headerPanel("Diabetes prediction"), + + sidebarPanel( + numericInput('glucose', 'Glucose mg/dl', 90, min = 50, max = 200, step = 5), + submitButton('Submit') + ), + mainPanel( + h3('Results of prediction'), + h4('You entered'), + verbatimTextOutput("inputValue"), + h4('Which resulted in a prediction of '), + verbatimTextOutput("prediction") + ) + ) +) +