Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9053da3

Browse files
committed
Updated shiny example
1 parent 2bb6c86 commit 9053da3

File tree

4 files changed

+75
-68
lines changed

4 files changed

+75
-68
lines changed

_posts/r/coupled-events/2016-02-24-shiny-coupled-event.Rmd renamed to _posts/r/coupled-events/2016-02-24-shiny-coupled-events.Rmd

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ ui <- fluidPage(
9494
column(6, plotlyOutput("Plot2", height = "600px"))),
9595
9696
tags$hr(),
97+
tags$blockquote("First drag a selection box in the scatter plot to populate the barchart. Then select one of the bars in the barchat
98+
to populate the boxplot"),
99+
97100
98101
# Second row
99102
fixedRow(
100103
column(3, plotlyOutput("Plot3", height = "600px")),
101-
column(9, plotlyOutput("Plot4", height = "600px")))
102-
)
104+
column(9, plotlyOutput("Plot4", height = "600px"))))
103105
```
104106

105107
### server.r
@@ -140,7 +142,9 @@ server <- function(input, output){
140142
summarize(Count = n()) %>%
141143
filter(Class == "malignant") %>%
142144
plot_ly(x = x, y = y, z = Count, type = "contour") %>%
143-
layout(title = "Contour map of number of malignant cases")
145+
layout(title = "Contour map of number of malignant cases",
146+
xaxis = list(title = input$featureInput1),
147+
yaxis = list(title = input$featureInput2))
144148
145149
})
146150
@@ -169,18 +173,15 @@ server <- function(input, output){
169173
group_by(x, y, Class) %>%
170174
summarize(Count = n())
171175
172-
# Assign colors
173-
plot.summ$color <- factor(x = plot.summ$Class, labels = c("FF7676","F6F49D"))
174-
175176
# Assign to parent frame
176177
plot.summ <<- plot.summ
177178
178179
179180
# Plot
180-
plot_ly(plot.summ, x = Class, y = Count, type = "bar", source = "select",
181-
marker = list(color = color)) %>%
182-
layout(title = "No. of Malignant and Benign cases in Selection",
183-
plot_bgcolor = "466C95")
181+
plot_ly(plot.summ, x = Class, y = Count, type = "bar", source = "select", color = Class) %>%
182+
layout(title = "No. of Malignant and Benign cases <br> in Selection",
183+
plot_bgcolor = "6A446F",
184+
yaxis = list(domain = c(0, 0.9)))
184185
})
185186
186187
# Coupled event 2
@@ -192,32 +193,33 @@ server <- function(input, output){
192193
# If NULL dont do anything
193194
if(is.null(event.data) == T) return(NULL)
194195
196+
195197
# If Malignant
196198
if(event.data[3] == "malignant"){
197199
198200
tab <- subset(plot.summ, Class == "malignant")
199201
200-
p1 <- plot_ly(tab, x = as.factor(Count), y = x, type = "box", showlegend = F) %>%
201-
layout(xaxis = list(title = "Count"),
202-
yaxis = list(title = input$featureInput1))
202+
p1 <- plot_ly(tab, x = x, y = Count, type = "box", showlegend = F) %>%
203+
layout(yaxis = list(title = "Count"),
204+
xaxis = list(title = input$featureInput1))
203205
204-
p2 <- plot_ly(tab, x = as.factor(Count), y = y, type = "box", showlegend = F) %>%
206+
p2 <- plot_ly(tab, x = y, y = Count, type = "box", showlegend = F) %>%
205207
layout(title = "Box plot for Malignant cases",
206-
xaxis = list(title = "Count"),
207-
yaxis = list(title = input$featureInput2))
208+
yaxis = list(title = "Count"),
209+
xaxis = list(title = input$featureInput2))
208210
209211
subplot(p1, p2)
210212
}else{
211213
tab <- subset(plot.summ, Class == "benign")
212214
213-
p1 <- plot_ly(tab, x = as.factor(Count), y = x, type = "box", showlegend = F) %>%
214-
layout(xaxis = list(title = "Count"),
215-
yaxis = list(title = input$featureInput1))
215+
p1 <- plot_ly(tab, x = x, y = Count, type = "box", showlegend = F) %>%
216+
layout(yaxis = list(title = "Count"),
217+
xaxis = list(title = input$featureInput1))
216218
217-
p2 <- plot_ly(tab, x = as.factor(Count), y = y, type = "box", showlegend = F) %>%
219+
p2 <- plot_ly(tab, x = y, y = Count, type = "box", showlegend = F) %>%
218220
layout(title = "Box plot for Benign cases",
219-
xaxis = list(title = "Count"),
220-
yaxis = list(title = input$featureInput2))
221+
yaxis = list(title = "Count"),
222+
xaxis = list(title = input$featureInput2))
221223
222224
subplot(p1, p2)
223225
}

_posts/r/coupled-events/2016-02-24-shiny-coupled-event.md renamed to _posts/r/coupled-events/2016-02-24-shiny-coupled-events.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ Information returned is of the following form:
2828

2929
Below is an example on how to couple events from multiple charts together in the same app. The `source` argument is used to bind an `event_data()` command to a specific plotly graph.
3030

31-
<hr>
32-
3331
## Shiny app
3432

3533
<iframe src="https://plotly.shinyapps.io/ShinyCoupledEvents/" width="100%" height=1600 scrolling="no" seamless="seamless" style="border: none"></iframe>
@@ -87,12 +85,14 @@ ui <- fluidPage(
8785
column(6, plotlyOutput("Plot2", height = "600px"))),
8886

8987
tags$hr(),
88+
tags$blockquote("First drag a selection box in the scatter plot to populate the barchart. Then select one of the bars in the barchat
89+
to populate the boxplot"),
90+
9091

9192
# Second row
9293
fixedRow(
9394
column(3, plotlyOutput("Plot3", height = "600px")),
94-
column(9, plotlyOutput("Plot4", height = "600px")))
95-
)
95+
column(9, plotlyOutput("Plot4", height = "600px"))))
9696
```
9797

9898
### server.r
@@ -134,7 +134,9 @@ server <- function(input, output){
134134
summarize(Count = n()) %>%
135135
filter(Class == "malignant") %>%
136136
plot_ly(x = x, y = y, z = Count, type = "contour") %>%
137-
layout(title = "Contour map of number of malignant cases")
137+
layout(title = "Contour map of number of malignant cases",
138+
xaxis = list(title = input$featureInput1),
139+
yaxis = list(title = input$featureInput2))
138140

139141
})
140142

@@ -163,18 +165,15 @@ server <- function(input, output){
163165
group_by(x, y, Class) %>%
164166
summarize(Count = n())
165167

166-
# Assign colors
167-
plot.summ$color <- factor(x = plot.summ$Class, labels = c("FF7676","F6F49D"))
168-
169168
# Assign to parent frame
170169
plot.summ <<- plot.summ
171170

172171

173172
# Plot
174-
plot_ly(plot.summ, x = Class, y = Count, type = "bar", source = "select",
175-
marker = list(color = color)) %>%
176-
layout(title = "No. of Malignant and Benign cases in Selection",
177-
plot_bgcolor = "466C95")
173+
plot_ly(plot.summ, x = Class, y = Count, type = "bar", source = "select", color = Class) %>%
174+
layout(title = "No. of Malignant and Benign cases <br> in Selection",
175+
plot_bgcolor = "6A446F",
176+
yaxis = list(domain = c(0, 0.9)))
178177
})
179178

180179
# Coupled event 2
@@ -186,32 +185,33 @@ server <- function(input, output){
186185
# If NULL dont do anything
187186
if(is.null(event.data) == T) return(NULL)
188187

188+
189189
# If Malignant
190190
if(event.data[3] == "malignant"){
191191

192192
tab <- subset(plot.summ, Class == "malignant")
193193

194-
p1 <- plot_ly(tab, x = as.factor(Count), y = x, type = "box", showlegend = F) %>%
195-
layout(xaxis = list(title = "Count"),
196-
yaxis = list(title = input$featureInput1))
194+
p1 <- plot_ly(tab, x = x, y = Count, type = "box", showlegend = F) %>%
195+
layout(yaxis = list(title = "Count"),
196+
xaxis = list(title = input$featureInput1))
197197

198-
p2 <- plot_ly(tab, x = as.factor(Count), y = y, type = "box", showlegend = F) %>%
198+
p2 <- plot_ly(tab, x = y, y = Count, type = "box", showlegend = F) %>%
199199
layout(title = "Box plot for Malignant cases",
200-
xaxis = list(title = "Count"),
201-
yaxis = list(title = input$featureInput2))
200+
yaxis = list(title = "Count"),
201+
xaxis = list(title = input$featureInput2))
202202

203203
subplot(p1, p2)
204204
}else{
205205
tab <- subset(plot.summ, Class == "benign")
206206

207-
p1 <- plot_ly(tab, x = as.factor(Count), y = x, type = "box", showlegend = F) %>%
208-
layout(xaxis = list(title = "Count"),
209-
yaxis = list(title = input$featureInput1))
207+
p1 <- plot_ly(tab, x = x, y = Count, type = "box", showlegend = F) %>%
208+
layout(yaxis = list(title = "Count"),
209+
xaxis = list(title = input$featureInput1))
210210

211-
p2 <- plot_ly(tab, x = as.factor(Count), y = y, type = "box", showlegend = F) %>%
211+
p2 <- plot_ly(tab, x = y, y = Count, type = "box", showlegend = F) %>%
212212
layout(title = "Box plot for Benign cases",
213-
xaxis = list(title = "Count"),
214-
yaxis = list(title = input$featureInput2))
213+
yaxis = list(title = "Count"),
214+
xaxis = list(title = input$featureInput2))
215215

216216
subplot(p1, p2)
217217
}

_posts/r/coupled-events/server.R

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ server <- function(input, output){
3434
summarize(Count = n()) %>%
3535
filter(Class == "malignant") %>%
3636
plot_ly(x = x, y = y, z = Count, type = "contour") %>%
37-
layout(title = "Contour map of number of malignant cases")
37+
layout(title = "Contour map of number of malignant cases",
38+
xaxis = list(title = input$featureInput1),
39+
yaxis = list(title = input$featureInput2))
3840

3941
})
4042

@@ -63,18 +65,15 @@ server <- function(input, output){
6365
group_by(x, y, Class) %>%
6466
summarize(Count = n())
6567

66-
# Assign colors
67-
plot.summ$color <- factor(x = plot.summ$Class, labels = c("FF7676","F6F49D"))
68-
6968
# Assign to parent frame
7069
plot.summ <<- plot.summ
7170

7271

7372
# Plot
74-
plot_ly(plot.summ, x = Class, y = Count, type = "bar", source = "select",
75-
marker = list(color = color)) %>%
76-
layout(title = "No. of Malignant and Benign cases in Selection",
77-
plot_bgcolor = "466C95")
73+
plot_ly(plot.summ, x = Class, y = Count, type = "bar", source = "select", color = Class) %>%
74+
layout(title = "No. of Malignant and Benign cases <br> in Selection",
75+
plot_bgcolor = "6A446F",
76+
yaxis = list(domain = c(0, 0.9)))
7877
})
7978

8079
# Coupled event 2
@@ -86,32 +85,33 @@ server <- function(input, output){
8685
# If NULL dont do anything
8786
if(is.null(event.data) == T) return(NULL)
8887

88+
8989
# If Malignant
9090
if(event.data[3] == "malignant"){
9191

9292
tab <- subset(plot.summ, Class == "malignant")
9393

94-
p1 <- plot_ly(tab, x = as.factor(Count), y = x, type = "box", showlegend = F) %>%
95-
layout(xaxis = list(title = "Count"),
96-
yaxis = list(title = input$featureInput1))
94+
p1 <- plot_ly(tab, x = x, y = Count, type = "box", showlegend = F) %>%
95+
layout(yaxis = list(title = "Count"),
96+
xaxis = list(title = input$featureInput1))
9797

98-
p2 <- plot_ly(tab, x = as.factor(Count), y = y, type = "box", showlegend = F) %>%
98+
p2 <- plot_ly(tab, x = y, y = Count, type = "box", showlegend = F) %>%
9999
layout(title = "Box plot for Malignant cases",
100-
xaxis = list(title = "Count"),
101-
yaxis = list(title = input$featureInput2))
100+
yaxis = list(title = "Count"),
101+
xaxis = list(title = input$featureInput2))
102102

103103
subplot(p1, p2)
104104
}else{
105105
tab <- subset(plot.summ, Class == "benign")
106106

107-
p1 <- plot_ly(tab, x = as.factor(Count), y = x, type = "box", showlegend = F) %>%
108-
layout(xaxis = list(title = "Count"),
109-
yaxis = list(title = input$featureInput1))
107+
p1 <- plot_ly(tab, x = x, y = Count, type = "box", showlegend = F) %>%
108+
layout(yaxis = list(title = "Count"),
109+
xaxis = list(title = input$featureInput1))
110110

111-
p2 <- plot_ly(tab, x = as.factor(Count), y = y, type = "box", showlegend = F) %>%
111+
p2 <- plot_ly(tab, x = y, y = Count, type = "box", showlegend = F) %>%
112112
layout(title = "Box plot for Benign cases",
113-
xaxis = list(title = "Count"),
114-
yaxis = list(title = input$featureInput2))
113+
yaxis = list(title = "Count"),
114+
xaxis = list(title = input$featureInput2))
115115

116116
subplot(p1, p2)
117117
}

_posts/r/coupled-events/ui.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,14 @@ ui <- fluidPage(
4747
column(6, plotlyOutput("Plot2", height = "600px"))),
4848

4949
tags$hr(),
50+
tags$blockquote("First drag a selection box in the scatter plot to populate the barchart. Then select one of the bars in the barchat
51+
to populate the boxplot"),
52+
5053

5154
# Second row
5255
fixedRow(
5356
column(3, plotlyOutput("Plot3", height = "600px")),
54-
column(9, plotlyOutput("Plot4", height = "600px")))
55-
)
57+
column(9, plotlyOutput("Plot4", height = "600px"))))
58+
59+
60+

0 commit comments

Comments
 (0)