Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >动态过滤相同/公共级别的闪亮应用程序

动态过滤相同/公共级别的闪亮应用程序
EN

Stack Overflow用户
提问于 2020-12-15 08:13:29
回答 1查看 206关注 0票数 0

我正在尝试一个带有3个动态过滤器的应用程序,其中每个过滤器都是前一个过滤器的子集。

然而,我取得了部分成功,因为对于某些数据,我有类似的级别/因素,这似乎导致了我的过滤器结果出现问题。

我似乎想不出如何解决"Spot“属性的公共级别问题。

有人有任何反馈吗?

谢谢!

我的应用程序:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
library(rstudioapi)
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
library(shinyWidgets)
library(readxl)
library(DT)
library(devtools)
library(dplyr)
library(tidyr)
library(tidyverse)
library(rgl)
library(rglwidget)


col_1 <- c("A1","A1","A1", "A2", "A2", "B1", "B2", "C1","C1","C1")
col_2 <- c("a",  "b", "c", "d", "e", "a", "b", "a",  "b", "c")
col_3 <- c("Benz",  "Audi", "Renault", "Ferrari", "Porsche", "Mercedes", "Benz", "Benz",  "Audi", "Renault")

data_1 <- data.frame(col_1, col_2, col_3, stringsAsFactors = TRUE)
colnames(data_1) <- c("Building", "Spot", "Car")

server <- function(input, output, session) {
  
  filterCars <- reactive({
    filterCar <- data_1
    filterCar <- droplevels.data.frame(filterCar)
    return(filterCar)
  })
  
  filterBuilding <- reactive({
    unique(as.character(filterCars()$Building))
  })
  
  output$filterBuilding <- renderUI({
    pickerInput(inputId = 'filter_Building', 'Building',
                choices = sort(filterBuilding()),
                multiple = TRUE,
                width = "1250px",
                options = list(`actions-box` = TRUE),
                selected = sort(as.character(filterCars()$Building)))
  })
  
  # # Subset dynamically the previous reactive filter #
  datasub1 <- reactive({
    data_1[data_1$Building == input$filter_Building,]
  })
  
  filterSpot <- reactive({
    unique(as.character(datasub1()$Spot))
  })
  
  output$filterSpot <- renderUI({
    pickerInput(inputId = 'filter_Spot', 'Spot',
                choices = sort(filterSpot()),
                multiple=TRUE,
                width = "1250px",
                options = list(`actions-box` = TRUE),
                selected = sort(as.character(filterCars()$Spot)))
  })
  
  # Subset dynamically the previous reactive filter #
  datasub2 <- reactive({
    data_1[data_1$Spot == input$filter_Spot,]
  })

  filterBrand <- reactive({
    unique(as.character(datasub2()$Car))
  })

  output$filterBrand <- renderUI({
    pickerInput(inputId = 'filter_Brand', 'ID',
                choices = sort(filterBrand()),
                multiple = TRUE,
                width = "1250px",
                selected = NULL,
                options = list("max-options" = 4, `actions-box` = TRUE))
  })
  
  
   output$databaseCars <- DT::renderDT({

    #  Subset for plotly reactivity
    Filter1 <- droplevels.data.frame(data_1)
    Filter2 <- filter(Filter1,
                      Filter1$Building %in% input$filter_Building,
                      Filter1$Spot %in% input$filter_Spot,
                      Filter1$Car %in% input$filter_Brand)

    # Plot
    datatable(Filter2,
              filter="none",
              selection="none",
              escape=FALSE,
              rownames = FALSE,
              # colnames = c("", ""),
              autoHideNavigation = TRUE,
              style = 'bootstrap4',
              options = list(searching = FALSE, # remove search option
                             ordering = FALSE, # remove sort option
                             paging = FALSE,  # remove paging
                             info = FALSE # remove bottom information
              )) %>%
      formatStyle(columns = 1, fontWeight = 'bold', `text-align` = 'left') # text to bold and lign left in first column
  })
  
}

# User Interface
ui <- fluidPage(
  
  mainPanel(
    
    fluidRow(
      column(12,
             uiOutput("filterBuilding")
      )),
    
    fluidRow(
      column(12,
             uiOutput("filterSpot")
      )),
    
    fluidRow(
      column(12,
             uiOutput("filterBrand")
      )),
    
    p(DTOutput('databaseCars'))
  )
)

shinyApp(ui, server)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-15 09:38:37

我发现了几个问题:

  • 每个变量可以有几个因素/选择,因此您需要使用%in%而不是==来过滤品牌的
  • ,您已经设置了selected = NULL,因此在默认的
  • 中没有选择任何品牌,因此建议在ui部分中创建UI元素并使用updatePickerInput更新它们,而不是使用renderUI,因为所有呈现都必须在服务器端完成,这可以减缓应用程序的速度(特别是如果您有几个并行用户,因为只有一个R处理H 213提供服务)。

以下是我的看法:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
library(shiny)
library(DT)
library(dplyr)
library(shinyWidgets)


col_1 <- c("A1","A1","A1", "A2", "A2", "B1", "B2", "C1","C1","C1")
col_2 <- c("a",  "b", "c", "d", "e", "a", "b", "a",  "b", "c")
col_3 <- c("Benz",  "Audi", "Renault", "Ferrari", "Porsche", "Mercedes", "Benz", "Benz",  "Audi", "Renault")

data_1 <- data.frame(col_1, col_2, col_3, stringsAsFactors = TRUE)
colnames(data_1) <- c("Building", "Spot", "Car")

server <- function(input, output, session) {
  
  filterCars <- reactive({
    filterCar <- data_1
    filterCar <- droplevels.data.frame(filterCar)
    return(filterCar)
  })
  
  
  filterBuilding <- reactive({
    unique(as.character(filterCars()$Building))
  })
  
  observeEvent(filterBuilding(), {
    updatePickerInput(session,
                      "filter_Building",
                      choices = filterBuilding(),
                      selected = sort(filterBuilding()))
  })
  
  # # Subset dynamically the previous reactive filter #
  datasub1 <- reactive({
    data_1[data_1$Building %in% input$filter_Building,]
  })
  
  filterSpot <- reactive({
    unique(as.character(datasub1()$Spot))
  })
  
  observeEvent(filterSpot(), {
    updatePickerInput(session,
                      "filter_Spot",
                      choices = sort(filterSpot()),
                      selected = sort(filterSpot()))
  })
  
  # Subset dynamically the previous reactive filter #
  datasub2 <- reactive({
    # browser()
    data_1[data_1$Spot %in% input$filter_Spot,]
  })
  
  filterBrand <- reactive({
    unique(as.character(datasub2()$Car))
  })
  
  observeEvent(filterBrand(), {
    updatePickerInput(session,
                      "filter_Brand",
                      choices = sort(filterBrand()),
                      selected = sort(filterBrand()))
  })
  
  
  output$databaseCars <- DT::renderDT({
    
    #  Subset for plotly reactivity
    Filter1 <- droplevels.data.frame(data_1)
    Filter2 <- filter(Filter1,
                      Filter1$Building %in% input$filter_Building,
                      Filter1$Spot %in% input$filter_Spot,
                      Filter1$Car %in% input$filter_Brand)
    
    # Plot
    datatable(Filter2,
              filter="none",
              selection="none",
              escape=FALSE,
              rownames = FALSE,
              # colnames = c("", ""),
              autoHideNavigation = TRUE,
              style = 'bootstrap4',
              options = list(searching = FALSE, # remove search option
                             ordering = FALSE, # remove sort option
                             paging = FALSE,  # remove paging
                             info = FALSE # remove bottom information
              )) %>%
      formatStyle(columns = 1, fontWeight = 'bold', `text-align` = 'left') # text to bold and lign left in first column
  })
  
}

# User Interface
ui <- fluidPage(
  
  mainPanel(
    
    fluidRow(
      column(12,
             pickerInput(inputId = 'filter_Building', 'Building',
                         choices = NULL,
                         multiple = TRUE,
                         width = "1250px",
                         options = list(`actions-box` = TRUE),
                         selected = NULL)
      )),
    
    fluidRow(
      column(12,
             pickerInput(inputId = 'filter_Spot', 'Spot',
                         choices = NULL,
                         multiple=TRUE,
                         width = "1250px",
                         options = list(`actions-box` = TRUE),
                         selected = NULL)
      )),
    
    fluidRow(
      column(12,
             pickerInput(inputId = 'filter_Brand', 'ID',
                         choices = NULL,
                         multiple = TRUE,
                         width = "1250px",
                         selected = NULL,
                         options = list("max-options" = 4, `actions-box` = TRUE))
      )),
    
    p(DTOutput('databaseCars'))
  )
)

shinyApp(ui, server)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65309601

复制
相关文章
双精度,单精度和半精度
浮点数是计算机上最常用的数据类型之一,有些语言甚至数值只有浮点型(Perl,Lua同学别跑,说的就是你)。
用户1148523
2019/05/27
6K0
ctype.h
摘自维基百科 http://zh.wikipedia.org/wiki/Ctype.h
用户7886150
2021/02/25
8320
python ctype模块 (一)
官网:https://docs.python.org/2.6/library/ctypes.html?highlight=ctype#module-ctypes ctypes 的简单使用。 ctyp
py3study
2020/01/08
8370
SpringBoot返回前端Long型丢失精度咋办
最近为Prong开发了一个基于snowflake算法的Java分布式ID组件,将实体主键从原来的String类型的UUID修改成了Long型的分布式ID。修改后发现前端显示的ID和数据库中的ID不一致。例如数据库中存储的是:812782555915911412,显示出来却成了812782555915911400,后面2位变成了0,精度丢失了:
用户3467126
2021/11/09
4.3K0
SpringBoot返回前端Long型丢失精度咋办
轮询和长轮询 轮询和长轮询
轮询和长轮询 轮询:客户端定时向服务器发送Ajax请求,服务器接到请求后马上返回响应信息并关闭连接。 优点:后端程序编写比较容易。 缺点:请求中有大半是无用,浪费带宽和服务器资源。 实例:适于小型应用。 长轮询:客户端向服务器发送Ajax请求,服务器接到请求后hold住连接,直到有新消息才返回响应信息并关闭连接,客户端处理完响应信息后再向服务器发送新的请求。 优点:在无消息的情况下不会频繁的请求。 缺点:服务器hold连接会消耗资源。 实例:WebQQ、Hi网页版、Facebook IM。 另外
大道七哥
2019/09/10
2.2K0
轮询和长轮询

            轮询和长轮询
轮询和长轮询_http长轮询
长轮询:说白了也是客户端请求服务端,但是服务端并不是即时返回,而是当有内容更新的时候才返回内容给客户端,从流程上讲,可以理解为服务器向客户端推送内容;
全栈程序员站长
2022/09/20
1.5K0
利用高精度拼接算法实现长柱形物体检测
今天跟大家分享的是我们在近几年多次成功在客户现场部署的利用高精度拼接算法实现长柱形物体检测方案。
小白学视觉
2022/09/28
3220
C++ AMP双精度Windows环境测试报告
测试日期:2014-2-26 测试环境:华硕ESC1000超算工作站 测试GPU:AMD FirePro S7000 测试系统:Win7 & Win 8 测试过程: 测试代码下载:完整的C++ AMP工程 参考材料: 微软对于C++ AMP双精度的描述为: (http://blogs.msdn.com/b/nativeconcurrency/archive/2012/02/07/double-precision-support-in-c-amp.aspx) A WDDM 1.1 drive
GPUS Lady
2018/03/30
1K0
python 与 C 的交互(ctype
对指针实例赋值只会改变其指向的内存地址,而不是改变内存的内容。指针实例有一个contents属性,返回这个指针所指向的对象。
py3study
2020/01/07
1.7K0
python 与 C 的交互(ctype
AMD 新卡皇,双精度达到2.53TFlops
在 AMD FirePro S9150 服务器 GPU 面前,强度最大的计算密集型工 作负载和复杂计算都不能构成挑战。它支持 OpenCL™ 1.2、16GB GDDR5 显存、最高可达 2.53 TFLOPS 的峰值双精度浮点运算性能和 最高可达 10.8 GFLOPS/W 的峰值双精度性能,这让您的选择毋庸 置疑。AMD FirePro S9150 GPU 能够提供无与伦比计算性能和每瓦特 性能。 GPU 计算性能处于业内领先地位 作为首款具有 ½ 比率双精度, 并突破 2.0 TFLOPS 双精
GPUS Lady
2018/03/30
1.6K0
小朋友学C语言(4):单精度浮点数与双精度浮点数
上节课 简单介绍了浮点数。计算机程序中的浮点数分为单精度浮点数和双精度浮点数。 单精度和双精度精确的范围不一样。 计算机里的最基本的存储单位用位(bit)来表示。bit只能用来存储0或1。 稍大一点的单位是字节(Byte,简写为B)。 再大一级的是千字节(kilo Bytes),用k来表示。 再大一级的单位是兆字节(Mega Bytes),用M来表示。一张照片的大小通常为1~3M。 再大一级的单位为G。一部高清电影的大小通常为1~2G。 再大一级的单位为T。 换算关系为: 1B = 8bit 1k =
海天一树
2018/04/17
2.9K0
小朋友学C语言(4):单精度浮点数与双精度浮点数
避坑 | 记一次前端长整数精度丢失问题
后端Java实现的接口如下,返回一个json格式的大整数 123456789123456789:
程序员鱼皮
2020/11/25
11.8K1
避坑 | 记一次前端长整数精度丢失问题
C/C++ 双精度double 数据相加出错缺陷解释
该文章讲述了作者在 C++ 社区遇到的一个问题,在两个数值相加时,程序显示的数值误差可能导致结果出错。作者通过使用 fabs 函数来修正误差,并给出了具体的解决方法。
林冠宏-指尖下的幽灵
2018/01/02
1.4K0
ANTNet|端侧架构,精度速度双超MobileNetV2
code: https://github.com/yyxiongzju/ANTNets
AIWalker
2020/08/10
1.7K0
ANTNet|端侧架构,精度速度双超MobileNetV2
spring ajax 长轮询,Ajax轮询和长轮询
缺点:Ajax轮询需要服务器有很快的处理速度与快速响应。long poll需要很高的并发,体现在同时容纳请求的能力。
全栈程序员站长
2022/11/04
1.4K0
【STM32H7的DSP教程】第30章 STM32H7复数浮点FFT(支持单精度和双精度)
完整版教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=94547 第30章 STM32H7复数浮点FFT(支持单精度和双精
Simon223
2021/06/17
1.1K0
【STM32H7的DSP教程】第30章       STM32H7复数浮点FFT(支持单精度和双精度)
【STM32H7的DSP教程】第31章 STM32H7实数浮点FFT(支持单精度和双精度)
完整版教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=94547 第31章 STM32H7实数浮点FFT(支持单精度和双精
Simon223
2021/06/17
1.1K0
【STM32H7的DSP教程】第31章       STM32H7实数浮点FFT(支持单精度和双精度)
C库函数手册(ctype.h)
ctype.h函数说明: int isalpha(int ch)  若ch是字母('A'-'Z','a'-'z')返回非0值,否则返回0 int isdigit(int ch)  若ch是数字('0'-'9')返回非0值,否则返回0 int isalnum(int ch)  若ch是字母('A'-'Z','a'-'z')或数字('0'-'9')返回非0值,否则返回0 int islower(int ch)  若ch是小写字母('a'-'z')返回非0值,否则返回0 int isupper(int ch) 
用户1215536
2018/02/05
7870
mysql长轮询_ajax的轮询和长轮询
轮询(polling):客户端按规定时间定时像服务端发送ajax请求,服务器接到请求后马上返回响应信息并关闭连接。
全栈程序员站长
2022/11/08
3.9K0
【STM32F407的DSP教程】第31章 STM32F407实数浮点FFT(支持单精度和双精度)
完整版教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=94547 第31章 STM32F407实数浮点FFT(支持单精度和
Simon223
2021/06/17
1.7K0
【STM32F407的DSP教程】第31章       STM32F407实数浮点FFT(支持单精度和双精度)

相似问题

精度长双精度比双精度差

14

c++中双精度和长双精度的区别

112

FFTW与长双精度

11

双精度和长整型数字的减法

52

试着访问长双数学宏和长双的精度

20
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文