仪表板在闪亮的应用程序中工作,但不在flexdashboard上
我正试图将闪亮的互动表整合到我已经存在的flexdashboard中 下面是使用dput()函数创建的数据结构 数据是关于8个不同的离线导航应用程序评论中的频繁词语 我使用以下代码创建了一个小的闪亮的应用程序(可以正常工作)仪表板在闪亮的应用程序中工作,但不在flexdashboard上,r,ggplot2,shiny,r-markdown,flexdashboard,R,Ggplot2,Shiny,R Markdown,Flexdashboard,我正试图将闪亮的互动表整合到我已经存在的flexdashboard中 下面是使用dput()函数创建的数据结构 数据是关于8个不同的离线导航应用程序评论中的频繁词语 我使用以下代码创建了一个小的闪亮的应用程序(可以正常工作) 库(闪亮) 图书馆(GG2) 图书馆(plyr) 图书馆(dplyr) #数据准备步骤 数据诀窍是只使用{r},而不使用include=FALSE。此外,我还更正了列和侧栏的定义 --- title: "Shiny in flexdashboar
库(闪亮)
图书馆(GG2)
图书馆(plyr)
图书馆(dplyr)
#数据准备步骤
数据诀窍是只使用{r}
,而不使用include=FALSE
。此外,我还更正了列和侧栏的定义
---
title: "Shiny in flexdashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(dplyr)
library(ggplot2)
library(shiny)
```
```{r}
#Import data
data <- read.csv("word_frequency_v2.csv")
my_colors2 <- c("#F29E4C", "#EFEA5A", "#6930C3", "#0077B6",
"#F94144", "#16DB93", "#621708", "#DA627D")
```
# Word frequency
Column {.sidebar}
-----------------------------------------------------------------------
Embedding a Shiny Module
```{r}
selectInput(inputId="app1",label="App1",choices = c("Genius"="Genius",
"TomTom"="TomTom",
"CoPilot"="CoPilot",
"Navmii"="Navmii",
"Sygic"="Sygic",
"Mapsme"="Mapsme",
"Waze"="Waze",
"Here"="Here"),
selected = "Genius",multiple = F)
selectInput(inputId="app2",label="App2",choices = c("Genius"="Genius",
"TomTom"="TomTom",
"CoPilot"="CoPilot",
"Navmii"="Navmii",
"Sygic"="Sygic",
"Mapsme"="Mapsme",
"Waze"="Waze",
"Here"="Here"),
selected = "TomTom",multiple = F)
```
Column
-----------------------------------------------------------------------
```{r}
renderPlot({
p2 <- data %>% ggplot()
if(input$app1 == "Genius"){
p2 <- p2 + geom_col(aes(x=reorder(words1, -pct1), y=pct1), fill = my_colors2[1]) +
geom_text(aes(x=reorder(words1, -pct1), y=pct1, label =pct1),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "TomTom"){
p2 <- p2 + geom_col(aes(x=reorder(words2, -pct2), y=pct2), fill = my_colors2[2]) +
geom_text(aes(x=reorder(words2, -pct2), y=pct2, label =pct2),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "CoPilot"){
p2 <- p2 + geom_col(aes(x=reorder(words3, -pct3), y=pct3), fill = my_colors2[3]) +
geom_text(aes(x=reorder(words3, -pct3), y=pct3, label =pct3),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Navmii"){
p2 <- p2 + geom_col(aes(x=reorder(words4, -pct4), y=pct4), fill = my_colors2[4]) +
geom_text(aes(x=reorder(words4, -pct4), y=pct4, label =pct4),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Sygic"){
p2 <- p2 + geom_col(aes(x=reorder(words5, -pct5), y=pct5), fill = my_colors2[5]) +
geom_text(aes(x=reorder(words5, -pct5), y=pct5, label =pct5),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Mapsme"){
p2 <- p2 + geom_col(aes(x=reorder(words6, -pct6), y=pct6), fill = my_colors2[6]) +
geom_text(aes(x=reorder(words6, -pct6), y=pct6, labe6 =pct6),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Waze"){
p2 <- p2 + geom_col(aes(x=reorder(words7, -pct7), y=pct7), fill = my_colors2[7]) +
geom_text(aes(x=reorder(words7, -pct7), y=pct7, label =pct7),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Here"){
p2 <- p2 + geom_col(aes(x=reorder(words8, -pct8), y=pct8), fill = my_colors2[8]) +
geom_text(aes(x=reorder(words8, -pct1), y=pct8, label =pct8),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}
p2 <- p2 + theme_bw()+
scale_y_continuous(limits = c(0,100), expand = c(0, 0)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, face = "bold")) +
labs(x="Words",y="Share of words in reviews",title=paste("Frequency of words -",input$app1,sep = " "))
p2
})
renderPlot({
p2 <- data %>% ggplot()
if(input$app2 == "Genius"){
p2 <- p2 + geom_col(aes(x=reorder(words1, -pct1), y=pct1), fill = my_colors2[1]) +
geom_text(aes(x=reorder(words1, -pct1), y=pct1, label =pct1),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "TomTom"){
p2 <- p2 + geom_col(aes(x=reorder(words2, -pct2), y=pct2), fill = my_colors2[2]) +
geom_text(aes(x=reorder(words2, -pct2), y=pct2, label =pct2),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "CoPilot"){
p2 <- p2 + geom_col(aes(x=reorder(words3, -pct3), y=pct3), fill = my_colors2[3]) +
geom_text(aes(x=reorder(words3, -pct3), y=pct3, label =pct3),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Navmii"){
p2 <- p2 + geom_col(aes(x=reorder(words4, -pct4), y=pct4), fill = my_colors2[4]) +
geom_text(aes(x=reorder(words4, -pct4), y=pct4, label =pct4),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Sygic"){
p2 <- p2 + geom_col(aes(x=reorder(words5, -pct5), y=pct5), fill = my_colors2[5]) +
geom_text(aes(x=reorder(words5, -pct5), y=pct5, label =pct5),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Mapsme"){
p2 <- p2 + geom_col(aes(x=reorder(words6, -pct6), y=pct6), fill = my_colors2[6]) +
geom_text(aes(x=reorder(words6, -pct6), y=pct6, label =pct6),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Waze"){
p2 <- p2 + geom_col(aes(x=reorder(words7, -pct7), y=pct7), fill = my_colors2[7]) +
geom_text(aes(x=reorder(words7, -pct7), y=pct7, label =pct7),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Here"){
p2 <- p2 + geom_col(aes(x=reorder(words8, -pct8), y=pct8), fill = my_colors2[8]) +
geom_text(aes(x=reorder(words8, -pct8), y=pct8, label =pct8),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}
p2 <- p2 + theme_bw()+
scale_y_continuous(limits = c(0,100), expand = c(0, 0)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, face = "bold")) +
labs(x="Words",y="Share of words in reviews",title=paste("Frequency of words -",input$app2,sep = " "))
p2
})
```
---
标题:“flexdashboard中的闪亮”
输出:
flexdashboard::flex_仪表板:
方向:列
垂直布局:填充
运行时间:闪亮
---
```{r设置,include=FALSE}
图书馆(dplyr)
图书馆(GG2)
图书馆(闪亮)
```
```{r}
#导入数据
数据
library(shiny)
library(ggplot2)
library(plyr)
library(dplyr)
# Data Preparation Steps
data <- read.csv("word_frequency_v2.csv")
my_colors2 <- c("#F29E4C", "#EFEA5A", "#6930C3", "#0077B6",
"#F94144", "#16DB93", "#621708", "#DA627D")
ui <- fluidPage(
# App title ----
titlePanel("Shiny - First Interactive Visualization Example"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
selectInput(inputId="app1",label="App1",choices = c("Genius"="Genius",
"TomTom"="TomTom",
"CoPilot"="CoPilot",
"Navmii"="Navmii",
"Sygic"="Sygic",
"Mapsme"="Mapsme",
"Waze"="Waze",
"Here"="Here"),
selected = "Genius",multiple = F),
selectInput(inputId="app2",label="App2",choices = c("Genius"="Genius",
"TomTom"="TomTom",
"CoPilot"="CoPilot",
"Navmii"="Navmii",
"Sygic"="Sygic",
"Mapsme"="Mapsme",
"Waze"="Waze",
"Here"="Here"),
selected = "TomTom",multiple = F)
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Histogram ----
plotOutput(outputId = "distPlot1"),
plotOutput(outputId = "distPlot2")
)
)
)
# Define server logic required to draw a histogram ----
server <- function(input, output){
# 1. It is "reactive" and therefore should be automatically
# re-executed when inputs (input$bins) change
# 2. Its output type is a plot
output$distPlot1 <- renderPlot({
p2 <- data %>% ggplot()
if(input$app1 == "Genius"){
p2 <- p2 + geom_col(aes(x=reorder(words1, -pct1), y=pct1), fill = my_colors2[1]) +
geom_text(aes(x=reorder(words1, -pct1), y=pct1, label =pct1),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "TomTom"){
p2 <- p2 + geom_col(aes(x=reorder(words2, -pct2), y=pct2), fill = my_colors2[2]) +
geom_text(aes(x=reorder(words2, -pct2), y=pct2, label =pct2),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "CoPilot"){
p2 <- p2 + geom_col(aes(x=reorder(words3, -pct3), y=pct3), fill = my_colors2[3]) +
geom_text(aes(x=reorder(words3, -pct3), y=pct3, label =pct3),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Navmii"){
p2 <- p2 + geom_col(aes(x=reorder(words4, -pct4), y=pct4), fill = my_colors2[4]) +
geom_text(aes(x=reorder(words4, -pct4), y=pct4, label =pct4),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Sygic"){
p2 <- p2 + geom_col(aes(x=reorder(words5, -pct5), y=pct5), fill = my_colors2[5]) +
geom_text(aes(x=reorder(words5, -pct5), y=pct5, label =pct5),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Mapsme"){
p2 <- p2 + geom_col(aes(x=reorder(words6, -pct6), y=pct6), fill = my_colors2[6]) +
geom_text(aes(x=reorder(words6, -pct6), y=pct6, labe6 =pct6),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Waze"){
p2 <- p2 + geom_col(aes(x=reorder(words7, -pct7), y=pct7), fill = my_colors2[7]) +
geom_text(aes(x=reorder(words7, -pct7), y=pct7, label =pct7),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Here"){
p2 <- p2 + geom_col(aes(x=reorder(words8, -pct8), y=pct8), fill = my_colors2[8]) +
geom_text(aes(x=reorder(words8, -pct1), y=pct8, label =pct8),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}
p2 <- p2 + theme_bw()+
scale_y_continuous(limits = c(0,100), expand = c(0, 0)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, face = "bold")) +
labs(x="Words",y="Share of words in reviews",title=paste("Frequency of words -",input$app1,sep = " "))
p2
})
output$distPlot2 <- renderPlot({
p2 <- data %>% ggplot()
if(input$app2 == "Genius"){
p2 <- p2 + geom_col(aes(x=reorder(words1, -pct1), y=pct1), fill = my_colors2[1]) +
geom_text(aes(x=reorder(words1, -pct1), y=pct1, label =pct1),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "TomTom"){
p2 <- p2 + geom_col(aes(x=reorder(words2, -pct2), y=pct2), fill = my_colors2[2]) +
geom_text(aes(x=reorder(words2, -pct2), y=pct2, label =pct2),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "CoPilot"){
p2 <- p2 + geom_col(aes(x=reorder(words3, -pct3), y=pct3), fill = my_colors2[3]) +
geom_text(aes(x=reorder(words3, -pct3), y=pct3, label =pct3),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Navmii"){
p2 <- p2 + geom_col(aes(x=reorder(words4, -pct4), y=pct4), fill = my_colors2[4]) +
geom_text(aes(x=reorder(words4, -pct4), y=pct4, label =pct4),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Sygic"){
p2 <- p2 + geom_col(aes(x=reorder(words5, -pct5), y=pct5), fill = my_colors2[5]) +
geom_text(aes(x=reorder(words5, -pct5), y=pct5, label =pct5),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Mapsme"){
p2 <- p2 + geom_col(aes(x=reorder(words6, -pct6), y=pct6), fill = my_colors2[6]) +
geom_text(aes(x=reorder(words6, -pct6), y=pct6, label =pct6),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Waze"){
p2 <- p2 + geom_col(aes(x=reorder(words7, -pct7), y=pct7), fill = my_colors2[7]) +
geom_text(aes(x=reorder(words7, -pct7), y=pct7, label =pct7),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Here"){
p2 <- p2 + geom_col(aes(x=reorder(words8, -pct8), y=pct8), fill = my_colors2[8]) +
geom_text(aes(x=reorder(words8, -pct8), y=pct8, label =pct8),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}
p2 <- p2 + theme_bw()+
scale_y_continuous(limits = c(0,100), expand = c(0, 0)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, face = "bold")) +
labs(x="Words",y="Share of words in reviews",title=paste("Frequency of words -",input$app2,sep = " "))
p2
})
}
shinyApp(ui = ui, server = server)
---
title: "Shiny in flexdashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(dplyr)
library(ggplot2)
library(shiny)
```
```{r}
#Import data
data <- read.csv("word_frequency_v2.csv")
my_colors2 <- c("#F29E4C", "#EFEA5A", "#6930C3", "#0077B6",
"#F94144", "#16DB93", "#621708", "#DA627D")
```
# Word frequency
### Embedding a Shiny Module {.sidebar}
```{r, include=FALSE}
selectInput(inputId="app1",label="App1",choices = c("Genius"="Genius",
"TomTom"="TomTom",
"CoPilot"="CoPilot",
"Navmii"="Navmii",
"Sygic"="Sygic",
"Mapsme"="Mapsme",
"Waze"="Waze",
"Here"="Here"),
selected = "Genius",multiple = F)
selectInput(inputId="app2",label="App2",choices = c("Genius"="Genius",
"TomTom"="TomTom",
"CoPilot"="CoPilot",
"Navmii"="Navmii",
"Sygic"="Sygic",
"Mapsme"="Mapsme",
"Waze"="Waze",
"Here"="Here"),
selected = "TomTom",multiple = F)
```
```{r, include=FALSE}
renderPlot({
p2 <- data %>% ggplot()
if(input$app1 == "Genius"){
p2 <- p2 + geom_col(aes(x=reorder(words1, -pct1), y=pct1), fill = my_colors2[1]) +
geom_text(aes(x=reorder(words1, -pct1), y=pct1, label =pct1),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "TomTom"){
p2 <- p2 + geom_col(aes(x=reorder(words2, -pct2), y=pct2), fill = my_colors2[2]) +
geom_text(aes(x=reorder(words2, -pct2), y=pct2, label =pct2),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "CoPilot"){
p2 <- p2 + geom_col(aes(x=reorder(words3, -pct3), y=pct3), fill = my_colors2[3]) +
geom_text(aes(x=reorder(words3, -pct3), y=pct3, label =pct3),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Navmii"){
p2 <- p2 + geom_col(aes(x=reorder(words4, -pct4), y=pct4), fill = my_colors2[4]) +
geom_text(aes(x=reorder(words4, -pct4), y=pct4, label =pct4),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Sygic"){
p2 <- p2 + geom_col(aes(x=reorder(words5, -pct5), y=pct5), fill = my_colors2[5]) +
geom_text(aes(x=reorder(words5, -pct5), y=pct5, label =pct5),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Mapsme"){
p2 <- p2 + geom_col(aes(x=reorder(words6, -pct6), y=pct6), fill = my_colors2[6]) +
geom_text(aes(x=reorder(words6, -pct6), y=pct6, labe6 =pct6),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Waze"){
p2 <- p2 + geom_col(aes(x=reorder(words7, -pct7), y=pct7), fill = my_colors2[7]) +
geom_text(aes(x=reorder(words7, -pct7), y=pct7, label =pct7),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Here"){
p2 <- p2 + geom_col(aes(x=reorder(words8, -pct8), y=pct8), fill = my_colors2[8]) +
geom_text(aes(x=reorder(words8, -pct1), y=pct8, label =pct8),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}
p2 <- p2 + theme_bw()+
scale_y_continuous(limits = c(0,100), expand = c(0, 0)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, face = "bold")) +
labs(x="Words",y="Share of words in reviews",title=paste("Frequency of words -",input$app1,sep = " "))
p2
})
renderPlot({
p2 <- data %>% ggplot()
if(input$app2 == "Genius"){
p2 <- p2 + geom_col(aes(x=reorder(words1, -pct1), y=pct1), fill = my_colors2[1]) +
geom_text(aes(x=reorder(words1, -pct1), y=pct1, label =pct1),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "TomTom"){
p2 <- p2 + geom_col(aes(x=reorder(words2, -pct2), y=pct2), fill = my_colors2[2]) +
geom_text(aes(x=reorder(words2, -pct2), y=pct2, label =pct2),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "CoPilot"){
p2 <- p2 + geom_col(aes(x=reorder(words3, -pct3), y=pct3), fill = my_colors2[3]) +
geom_text(aes(x=reorder(words3, -pct3), y=pct3, label =pct3),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Navmii"){
p2 <- p2 + geom_col(aes(x=reorder(words4, -pct4), y=pct4), fill = my_colors2[4]) +
geom_text(aes(x=reorder(words4, -pct4), y=pct4, label =pct4),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Sygic"){
p2 <- p2 + geom_col(aes(x=reorder(words5, -pct5), y=pct5), fill = my_colors2[5]) +
geom_text(aes(x=reorder(words5, -pct5), y=pct5, label =pct5),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Mapsme"){
p2 <- p2 + geom_col(aes(x=reorder(words6, -pct6), y=pct6), fill = my_colors2[6]) +
geom_text(aes(x=reorder(words6, -pct6), y=pct6, label =pct6),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Waze"){
p2 <- p2 + geom_col(aes(x=reorder(words7, -pct7), y=pct7), fill = my_colors2[7]) +
geom_text(aes(x=reorder(words7, -pct7), y=pct7, label =pct7),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Here"){
p2 <- p2 + geom_col(aes(x=reorder(words8, -pct8), y=pct8), fill = my_colors2[8]) +
geom_text(aes(x=reorder(words8, -pct8), y=pct8, label =pct8),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}
p2 <- p2 + theme_bw()+
scale_y_continuous(limits = c(0,100), expand = c(0, 0)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, face = "bold")) +
labs(x="Words",y="Share of words in reviews",title=paste("Frequency of words -",input$app2,sep = " "))
p2
})
```
---
title: "Shiny in flexdashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(dplyr)
library(ggplot2)
library(shiny)
```
```{r}
#Import data
data <- read.csv("word_frequency_v2.csv")
my_colors2 <- c("#F29E4C", "#EFEA5A", "#6930C3", "#0077B6",
"#F94144", "#16DB93", "#621708", "#DA627D")
```
# Word frequency
Column {.sidebar}
-----------------------------------------------------------------------
Embedding a Shiny Module
```{r}
selectInput(inputId="app1",label="App1",choices = c("Genius"="Genius",
"TomTom"="TomTom",
"CoPilot"="CoPilot",
"Navmii"="Navmii",
"Sygic"="Sygic",
"Mapsme"="Mapsme",
"Waze"="Waze",
"Here"="Here"),
selected = "Genius",multiple = F)
selectInput(inputId="app2",label="App2",choices = c("Genius"="Genius",
"TomTom"="TomTom",
"CoPilot"="CoPilot",
"Navmii"="Navmii",
"Sygic"="Sygic",
"Mapsme"="Mapsme",
"Waze"="Waze",
"Here"="Here"),
selected = "TomTom",multiple = F)
```
Column
-----------------------------------------------------------------------
```{r}
renderPlot({
p2 <- data %>% ggplot()
if(input$app1 == "Genius"){
p2 <- p2 + geom_col(aes(x=reorder(words1, -pct1), y=pct1), fill = my_colors2[1]) +
geom_text(aes(x=reorder(words1, -pct1), y=pct1, label =pct1),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "TomTom"){
p2 <- p2 + geom_col(aes(x=reorder(words2, -pct2), y=pct2), fill = my_colors2[2]) +
geom_text(aes(x=reorder(words2, -pct2), y=pct2, label =pct2),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "CoPilot"){
p2 <- p2 + geom_col(aes(x=reorder(words3, -pct3), y=pct3), fill = my_colors2[3]) +
geom_text(aes(x=reorder(words3, -pct3), y=pct3, label =pct3),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Navmii"){
p2 <- p2 + geom_col(aes(x=reorder(words4, -pct4), y=pct4), fill = my_colors2[4]) +
geom_text(aes(x=reorder(words4, -pct4), y=pct4, label =pct4),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Sygic"){
p2 <- p2 + geom_col(aes(x=reorder(words5, -pct5), y=pct5), fill = my_colors2[5]) +
geom_text(aes(x=reorder(words5, -pct5), y=pct5, label =pct5),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Mapsme"){
p2 <- p2 + geom_col(aes(x=reorder(words6, -pct6), y=pct6), fill = my_colors2[6]) +
geom_text(aes(x=reorder(words6, -pct6), y=pct6, labe6 =pct6),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Waze"){
p2 <- p2 + geom_col(aes(x=reorder(words7, -pct7), y=pct7), fill = my_colors2[7]) +
geom_text(aes(x=reorder(words7, -pct7), y=pct7, label =pct7),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app1 == "Here"){
p2 <- p2 + geom_col(aes(x=reorder(words8, -pct8), y=pct8), fill = my_colors2[8]) +
geom_text(aes(x=reorder(words8, -pct1), y=pct8, label =pct8),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}
p2 <- p2 + theme_bw()+
scale_y_continuous(limits = c(0,100), expand = c(0, 0)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, face = "bold")) +
labs(x="Words",y="Share of words in reviews",title=paste("Frequency of words -",input$app1,sep = " "))
p2
})
renderPlot({
p2 <- data %>% ggplot()
if(input$app2 == "Genius"){
p2 <- p2 + geom_col(aes(x=reorder(words1, -pct1), y=pct1), fill = my_colors2[1]) +
geom_text(aes(x=reorder(words1, -pct1), y=pct1, label =pct1),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "TomTom"){
p2 <- p2 + geom_col(aes(x=reorder(words2, -pct2), y=pct2), fill = my_colors2[2]) +
geom_text(aes(x=reorder(words2, -pct2), y=pct2, label =pct2),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "CoPilot"){
p2 <- p2 + geom_col(aes(x=reorder(words3, -pct3), y=pct3), fill = my_colors2[3]) +
geom_text(aes(x=reorder(words3, -pct3), y=pct3, label =pct3),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Navmii"){
p2 <- p2 + geom_col(aes(x=reorder(words4, -pct4), y=pct4), fill = my_colors2[4]) +
geom_text(aes(x=reorder(words4, -pct4), y=pct4, label =pct4),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Sygic"){
p2 <- p2 + geom_col(aes(x=reorder(words5, -pct5), y=pct5), fill = my_colors2[5]) +
geom_text(aes(x=reorder(words5, -pct5), y=pct5, label =pct5),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Mapsme"){
p2 <- p2 + geom_col(aes(x=reorder(words6, -pct6), y=pct6), fill = my_colors2[6]) +
geom_text(aes(x=reorder(words6, -pct6), y=pct6, label =pct6),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Waze"){
p2 <- p2 + geom_col(aes(x=reorder(words7, -pct7), y=pct7), fill = my_colors2[7]) +
geom_text(aes(x=reorder(words7, -pct7), y=pct7, label =pct7),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}else if(input$app2 == "Here"){
p2 <- p2 + geom_col(aes(x=reorder(words8, -pct8), y=pct8), fill = my_colors2[8]) +
geom_text(aes(x=reorder(words8, -pct8), y=pct8, label =pct8),
position = position_dodge(0.9), size = 3.5, fontface = "bold", vjust = -1)
}
p2 <- p2 + theme_bw()+
scale_y_continuous(limits = c(0,100), expand = c(0, 0)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, face = "bold")) +
labs(x="Words",y="Share of words in reviews",title=paste("Frequency of words -",input$app2,sep = " "))
p2
})
```