2018-10-26
閱讀量:
1399
shiny應(yīng)用程序的搭建--滑動(dòng)條

sliders這個(gè)例子展示的是滑動(dòng)條(slider)控件的功能,包括產(chǎn)生動(dòng)畫效果。要運(yùn)行這個(gè)例子,只需鍵入:
> library(shiny)
> runExample("05_sliders")
定制化滑動(dòng)條
slider控件功能非常強(qiáng)大,同時(shí)也可以定制化。它支持的特性有:
- 既可以輸入單個(gè)的值,也可以輸入一個(gè)范圍。
- 自定義顯示值的格式(比如,貨幣格式)
- 讓滑動(dòng)條在一定范圍內(nèi)自動(dòng)滑動(dòng)
滑動(dòng)條控件是由調(diào)用sliderInput
函數(shù)生成的。ui.R文件展示的是多種選項(xiàng)的滑動(dòng)條。library(shiny)
# Define UI for slider demo application
shinyUI(pageWithSidebar(
# Application title
headerPanel("Sliders"),
# Sidebar with sliders that demonstrate various available options
sidebarPanel(
# Simple integer interval
sliderInput("integer",
"Integer:",
min=0,
max=1000,
value=500),
# Decimal interval with step value
sliderInput("decimal",
"Decimal:",
min
=
0,
max
=
1,
value
=
0.5,
step=
0.1),
# Specification of range within an interval
sliderInput("range",
"Range:",
min
=
1,
max
=
1000,
value
=
c(200,500)),
# Provide a custom currency format for value display, with basic animation
sliderInput("format",
"Custom Format:",
min
=
0,
max
=
10000,
value
=
0,
step
=
2500,
format="$#,##0",
locale="us",
animate=TRUE),
# Animation with custom interval (in ms) to control speed, plus looping
sliderInput("animation",
"Looping Animation:",
1,
2000,
1,
step
=
10,
animate=animationOptions(interval=300,
loop=T))
),
# Show a table summarizing the values entered
mainPanel(
tableOutput("values")
)
))
服務(wù)端腳本
slider應(yīng)用程序的服務(wù)端是很簡(jiǎn)單的:它創(chuàng)建了個(gè)數(shù)據(jù)框,用來存放所有輸入值,然后把它渲染到HTML表中。
library(shiny)
# Define server logic for slider examples
shinyServer(function(input,
output)
{
# Reactive expression to compose a data frame containing all of the values
sliderValues
<-
reactive({
# Compose data frame
data.frame(
Name
=
c("Integer",
"Decimal",
"Range",
"Custom Format",
"Animation"),
Value
=
as.character(c(input$integer,
input$decimal,
paste(input$range,
collapse=' '),
input$format,
input$animation)),
stringsAsFactors=FALSE)
})
# Show the values using an HTML table
output$values
<-
renderTable({
sliderValues()
})
})






評(píng)論(0)


暫無數(shù)據(jù)
CDA考試動(dòng)態(tài)
CDA報(bào)考指南
推薦帖子
0條評(píng)論
0條評(píng)論
0條評(píng)論