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

如何解决如何在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.5,10.1,9.4,9,8.3,8.3),words2 = structure(c(1L,13L
    ),"download","just","now","time","tom","tomtom","work","year"),pct2 = c(69.1,32.9,27.3,25,21.4,20,16.6,16.2,14.7,13.1,13,12.7,12.2,11.8,10.4,10.3,10.2
    ),words3 = structure(c(1L,13L,7L),"copilot","new","version",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.5,11.5,10.9,10.6,10.5),words4 = structure(c(1L,17L),"doesnt","even","find","navmii","tri",pct4 = c(56.1,41.2,36.5,32.5,22.6,20.9,18.9,15.8,14.1,12.9,12.4,11.7,11.3,11.1,10.1),words5 = structure(c(1L,"best","gps","love","nice","offlin","sygic",pct5 = c(39.7,23.5,20.5,19.3,13.8,10.2,8.6,7.7,6.7,6.1,6,5.9,5.5,5.1,5,4.9),words6 = structure(c(1L,12L),"help","thank","travel",pct6 = c(37.4,23,20.7,13.3,13.2,9.1,6.5,5.6,5.4,4.9,4.8,4.6),words7 = structure(c(1L,2L),"drive","googl","traffic","waze",pct7 = c(57.9,32.4,24.6,20.3,15.9,15.2,12.8,12.3,10,9.9,9.7,9.1),words8 = structure(c(1L,3L),"better",pct8 = c(44.6,39.3,25.2,22.3,15.4,12.6,8.8,8.7,7.3,7.1,6.8,6.6,6.4,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",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,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,y=pct2,label =pct2),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,y=pct3,label =pct3),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,y=pct4,label =pct4),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,y=pct5,label =pct5),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,y=pct6,labe6 =pct6),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,y=pct7,label =pct7),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,y=pct8,label =pct8),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,vjust = -1)
    }else if(input$app2 == "TomTom"){
      p2 <- p2 + geom_col(aes(x=reorder(words2,vjust = -1)
    }else if(input$app2 == "CoPilot"){
      p2 <- p2 + geom_col(aes(x=reorder(words3,vjust = -1)
    }else if(input$app2 == "Navmii"){
      p2 <- p2 + geom_col(aes(x=reorder(words4,vjust = -1)
    }else if(input$app2 == "Sygic"){
      p2 <- p2 + geom_col(aes(x=reorder(words5,vjust = -1)
    }else if(input$app2 == "Mapsme"){
      p2 <- p2 + geom_col(aes(x=reorder(words6,label =pct6),vjust = -1)
    }else if(input$app2 == "Waze"){
      p2 <- p2 + geom_col(aes(x=reorder(words7,vjust = -1)
    }else if(input$app2 == "Here"){
      p2 <- p2 + geom_col(aes(x=reorder(words8,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","#DA627D")
```

# Word frequency

### Embedding a Shiny Module {.sidebar}

```{r,include=FALSE}
selectInput(inputId="app1",multiple = F)
      
selectInput(inputId="app2",multiple = F)
```

```{r,include=FALSE}
renderPlot({
    
    p2 <- data %>% ggplot()
    if(input$app1 == "Genius"){
      p2 <- p2 + geom_col(aes(x=reorder(words1,sep = " "))
    
    p2
  })
  
renderPlot({
    
    p2 <- data %>% ggplot()
    if(input$app2 == "Genius"){
      p2 <- p2 + geom_col(aes(x=reorder(words1,sep = " "))
    
    p2
  })
```

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-