-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshiny_AAA.R
67 lines (44 loc) · 1.65 KB
/
shiny_AAA.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#R group
require(shiny)
nameList=as.character(rownames(mtcars))
shinyUI <- fluidPage(
sidebarPanel(
tags$head(tags$script(src="enterButton.js")),
fluidRow(selectInput("name",label = "Model",choices = c("",nameList))),
fluidRow(sliderInput("hp","Horsepower range",min =50 ,max=350,value=c(50,150))),
fluidRow(actionButton("submit",label = "Submit"))
),
mainPanel(
dataTableOutput("res"),
conditionalPanel(
condition="output.res",fluidRow(downloadLink("resTable","Download table"),
fluidRow(downloadLink("priceList","Download price list")))
)
))
#R group
require(shiny)
shinyServer <- function(input, output) {
res=eventReactive(input$submit,{
name=as.character(input$name)
minHp=input$hp[1]
maxHp=input$hp[2]
res=mtcars
if (name!="") {
res=mtcars[name,]
}
res=res[res$hp<maxHp & res$hp>minHp,]
validate(need(nrow(res)>0, "No matches found"))
return(res)
})
output$res=renderDataTable({
res=res()
},options=list(hover = T, bordered = T, align="c", colnames = T, rownames = T, na="NA"))
output$resTable=downloadHandler(filename="data_table.csv",
content = function(file) {
write.csv(res,file,row.names = F)
}, contentType = "text/csv")
output$priceList=downloadHandler(filename = "cars_prices.csv",
content=function(file){
file.copy("price_list.csv")
},contentType = "text/csv")
}