如何在Flexdashboard中运行闪亮的应用程序

时间:2020-08-20 22:13:04

标签: r ggplot2 shiny r-markdown flexdashboard

我正在尝试将闪亮的交互式工作表合并到我现有的flexdashboard中。

这是使用dput()函数创建的数据结构

structure(list(words1 = structure(c(1L, 10L, 19L, 20L, 7L, 8L, 
3L, 15L, 2L, 9L, 11L, 14L, 12L, 4L, 5L, 6L, 16L, 18L, 17L, 13L
), .Label = c("app", "can", "connect", "dont", "free", "get", 
"good", "great", "like", "map", "navig", "need", "one", "phone", 
"purchas", "road", "rout", "updat", "use", "work"), class = "factor"), 
    pct1 = c(70.8, 40.4, 26.4, 25.6, 22.7, 18.4, 13.7, 11.2, 
    10.8, 10.8, 10.8, 10.5, 10.5, 10.1, 9.4, 9.4, 9, 8.3, 8.3, 
    8.3), words2 = structure(c(1L, 18L, 8L, 19L, 16L, 4L, 17L, 
    5L, 15L, 12L, 14L, 6L, 3L, 11L, 20L, 9L, 10L, 2L, 7L, 13L
    ), .Label = c("app", "download", "get", "good", "great", 
    "just", "like", "map", "navig", "need", "now", "phone", "rout", 
    "time", "tom", "tomtom", "updat", "use", "work", "year"), class = "factor"), 
    pct2 = c(69.1, 32.9, 27.3, 25, 21.4, 20, 16.6, 16.2, 14.7, 
    13.1, 13, 13, 13, 12.7, 12.2, 11.8, 11.2, 10.4, 10.3, 10.2
    ), words3 = structure(c(1L, 17L, 8L, 19L, 16L, 4L, 12L, 14L, 
    2L, 5L, 20L, 15L, 13L, 3L, 18L, 11L, 9L, 6L, 10L, 7L), .Label = c("app", 
    "copilot", "get", "good", "great", "just", "like", "map", 
    "navig", "need", "new", "now", "road", "rout", "time", "updat", 
    "use", "version", "work", "year"), class = "factor"), pct3 = c(57.9, 
    45.7, 30.1, 21.7, 19.5, 19, 18.5, 18, 17.1, 16.7, 14.9, 14.6, 
    14, 12.7, 12.5, 12.2, 11.5, 10.9, 10.6, 10.5), words4 = structure(c(1L, 
    19L, 11L, 20L, 8L, 18L, 14L, 15L, 9L, 7L, 16L, 4L, 12L, 10L, 
    6L, 3L, 2L, 13L, 5L, 17L), .Label = c("app", "can", "doesnt", 
    "download", "even", "find", "get", "good", "great", "just", 
    "map", "navig", "navmii", "now", "rout", "time", "tri", "updat", 
    "use", "work"), class = "factor"), pct4 = c(56.1, 41.2, 36.5, 
    32.5, 22.6, 20.9, 18.9, 15.8, 14.9, 14.1, 14, 12.9, 12.4, 
    11.7, 11.3, 11.1, 10.9, 10.6, 10.3, 10.1), words5 = structure(c(1L, 
    4L, 19L, 10L, 6L, 11L, 20L, 2L, 16L, 18L, 12L, 17L, 5L, 8L, 
    9L, 15L, 14L, 3L, 13L, 7L), .Label = c("app", "best", "get", 
    "good", "gps", "great", "just", "like", "love", "map", "navig", 
    "nice", "now", "offlin", "rout", "sygic", "time", "updat", 
    "use", "work"), class = "factor"), pct5 = c(39.7, 23.5, 20.5, 
    19.3, 13.8, 11.3, 10.5, 10.2, 8.6, 7.7, 6.7, 6.7, 6.1, 6, 
    6, 5.9, 5.5, 5.1, 5, 4.9), words6 = structure(c(1L, 10L, 
    19L, 5L, 6L, 14L, 2L, 20L, 13L, 11L, 7L, 17L, 9L, 15L, 4L, 
    8L, 16L, 3L, 18L, 12L), .Label = c("app", "best", "can", 
    "download", "good", "great", "help", "like", "love", "map", 
    "navig", "need", "nice", "offlin", "rout", "thank", "travel", 
    "updat", "use", "work"), class = "factor"), pct6 = c(37.4, 
    26.4, 23, 20.7, 13.3, 13.2, 10.6, 9.1, 6.5, 6.1, 6, 6, 5.6, 
    5.4, 5.1, 5.1, 4.9, 4.9, 4.8, 4.6), words7 = structure(c(1L, 
    18L, 19L, 11L, 15L, 20L, 14L, 6L, 5L, 8L, 10L, 4L, 7L, 17L, 
    3L, 9L, 13L, 16L, 12L, 2L), .Label = c("app", "best", "drive", 
    "get", "good", "googl", "gps", "great", "like", "love", "map", 
    "navig", "road", "rout", "time", "traffic", "updat", "use", 
    "waze", "work"), class = "factor"), pct7 = c(57.9, 32.4, 
    24.6, 20.3, 18.9, 17.1, 15.9, 15.2, 12.8, 12.3, 12.2, 11.8, 
    11.8, 10.9, 10, 9.9, 9.7, 9.7, 9.4, 9.1), words8 = structure(c(1L, 
    12L, 19L, 15L, 6L, 13L, 2L, 20L, 9L, 5L, 7L, 18L, 11L, 16L, 
    10L, 17L, 8L, 14L, 4L, 3L), .Label = c("app", "best", "better", 
    "can", "download", "good", "googl", "gps", "great", "like", 
    "love", "map", "navig", "need", "offlin", "rout", "time", 
    "updat", "use", "work"), class = "factor"), pct8 = c(44.6, 
    39.3, 25.2, 22.3, 18.5, 15.4, 15.4, 14.1, 12.6, 8.8, 8.7, 
    8.6, 7.3, 7.1, 6.8, 6.6, 6.6, 6.4, 6, 5.5)), class = "data.frame", row.names = c(NA, 
-20L))

数据如下:

    words1 pct1   words2 pct2  words3 pct3   words4 pct4 words5 pct5   words6 pct6  words7 pct7   words8 pct8
1      app 70.8      app 69.1     app 57.9      app 56.1    app 39.7      app 37.4     app 57.9      app 44.6
2      map 40.4      use 32.9     use 45.7      use 41.2   good 23.5      map 26.4     use 32.4      map 39.3
3      use 26.4      map 27.3     map 30.1      map 36.5    use 20.5      use 23.0    waze 24.6      use 25.2
4     work 25.6     work 25.0    work 21.7     work 32.5    map 19.3     good 20.7     map 20.3   offlin 22.3
5     good 22.7   tomtom 21.4   updat 19.5     good 22.6  great 13.8    great 13.3    time 18.9     good 18.5
6    great 18.4     good 20.0    good 19.0    updat 20.9  navig 11.3   offlin 13.2    work 17.1    navig 15.4
7  connect 13.7    updat 16.6     now 18.5      now 18.9   work 10.5     best 10.6    rout 15.9     best 15.4
8  purchas 11.2    great 16.2    rout 18.0     rout 15.8   best 10.2     work  9.1   googl 15.2     work 14.1
9      can 10.8      tom 14.7 copilot 17.1    great 14.9  sygic  8.6     nice  6.5    good 12.8    great 12.6
10    like 10.8    phone 13.1   great 16.7      get 14.1  updat  7.7    navig  6.1   great 12.3 download  8.8
11   navig 10.8     time 13.0    year 14.9     time 14.0   nice  6.7     help  6.0    love 12.2    googl  8.7
12   phone 10.5     just 13.0    time 14.6 download 12.9   time  6.7   travel  6.0     get 11.8    updat  8.6
13    need 10.5      get 13.0    road 14.0    navig 12.4    gps  6.1     love  5.6     gps 11.8     love  7.3
14    dont 10.1      now 12.7     get 12.7     just 11.7   like  6.0     rout  5.4   updat 10.9     rout  7.1
15    free  9.4     year 12.2 version 12.5     find 11.3   love  6.0 download  5.1   drive 10.0     like  6.8
16     get  9.4    navig 11.8     new 12.2   doesnt 11.1   rout  5.9     like  5.1    like  9.9     time  6.6
17    road  9.0     need 11.2   navig 11.5      can 10.9 offlin  5.5    thank  4.9    road  9.7      gps  6.6
18   updat  8.3 download 10.4    just 10.9   navmii 10.6    get  5.1      can  4.9 traffic  9.7     need  6.4
19    rout  8.3     like 10.3    need 10.6     even 10.3    now  5.0    updat  4.8   navig  9.4      can  6.0
20     one  8.3     rout 10.2    like 10.5      tri 10.1   just  4.9     need  4.6    best  9.1   better  5.5

数据是关于8个不同的离线导航应用的评论中的常用词。

我使用以下代码创建了闪亮的小型应用程序(有效)

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)

现在,我正在尝试使用该代码,并使用下面的代码将其合并到我现有的flexdashboard中,但是我无法使其正常工作。

---
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
  })
```

如果我运行rmarkdown:render("filename.Rmd"),则会出现以下错误:未提供html_dependency的路径

如果我运行rmarkdown:run("filename.Rmd"),则会得到一个不显示任何过滤器或图表的应用程序。 我想尽可能地运行render函数,因为我以前用过以前的flexdashboard来做到这一点,如果将仪表板导出到.html文件,一切看起来都会更好。

0 个答案:

没有答案