15
Prepared by VOLKAN OBAN Some Examples in R: Drop-Down Combo Boxes in R. Example 1-

Some Examples in R

Embed Size (px)

Citation preview

Page 1: Some Examples in R

Prepared by VOLKAN OBAN

Some Examples in R:

Drop-Down Combo Boxes in R.

Example 1-

Page 2: Some Examples in R

Example 2-

Example 3

library(shiny) runApp(list( ui = bootstrapPage( numericInput('n', 'Enter 3 for condition', 3, 0, 10), conditionalPanel(condition="input.n==3", div(style="display:inline-block", tags$label('Menu1', `for` = 'Sample'), tags$select(id = 'Sample', class="input-small", tagList(mapply(tags$option, value = 1:10, paste0(letters[1:10], 1:10), SIMPLIFY=FALSE))) ), div(style="display:inline-block", tags$label('Menu2', `for` = 'Sample1'), tags$select(id = 'Sample1', class="input-small", tagList(mapply(tags$option, value = 1:2, paste0(letters[1:2], 1:2), SIMPLIFY=FALSE))) ) ) , textOutput("cond") ), server = function(input, output) { output$cond <- renderText({ if(input$n == 3){ paste0("Sample value selected =", input$Sample, " Sample1 value selected =",input$Sample1) } }) } ))

Page 3: Some Examples in R
Page 4: Some Examples in R

Example:

require(tcltk) tclRequire("BWidget") tt <- tktoplevel() tkgrid(tklabel(tt,text="What's your favorite fruit?")) fruits <- c("Apple","Orange","Banana","Pear") comboBox <- tkwidget(tt,"ComboBox",editable=FALSE,values=fruits) tkgrid(comboBox) OnOK <- function() { fruitChoice <- fruits[as.numeric(tclvalue(tkcmd(comboBox,"getvalue")))+1] tkdestroy(tt) msg <- paste("Good choice! ",fruitChoice,"s are delicious!",sep="") tkmessageBox(title="Fruit Choice",message=msg) } OK.but <-tkbutton(tt,text=" OK ",command=OnOK) tkgrid(OK.but) tkfocus(tt)

EXAMPLE: dygraphs

> library(dygraphs) > lungDeaths <- cbind(mdeaths, fdeaths) > dygraph(lungDeaths)

Page 5: Some Examples in R

e

Page 6: Some Examples in R

Example: Shiny Dashboard. library(shiny)

library(shinydashboard)

Ref: https://rstudio.github.io/shinydashboard/structure.html

Page 7: Some Examples in R
Page 8: Some Examples in R
Page 9: Some Examples in R
Page 10: Some Examples in R
Page 11: Some Examples in R
Page 12: Some Examples in R

Reference and codes: shiny.rstudio.com/gallery/

Page 13: Some Examples in R

Example:

Page 14: Some Examples in R

Reference and codes: http://shiny.rstudio.com/gallery/datatables-demo.html

Page 15: Some Examples in R

Reference:

• http://stackoverflow.com/questions/3574114/drop-down-list-implementation-in-r

• http://shiny.rstudio.com/gallery/select-box.html • http://mcu.edu.tw/~chenmh/teaching/project/r/reference/RTclTkExamples/DropDown.html • http://shiny.rstudio.com/gallery/