通过selectinput在闪亮的应用程序中选择列

如何解决通过selectinput在闪亮的应用程序中选择列

我正在尝试构建一个闪亮的应用程序,这很不错,但是我试图将我的数据框中的一列放入selectinput中,但是到目前为止,还没有找到解决方案。我有一列包含505个因数的列,称为AAPL,AAL等。我希望在selectinput中包含这些因数,以便您可以从这505个因数中进行选择,这是我现在的代码,以及我正在尝试的列名进入selectinput的是bcl-data $ Name。

var myArray = [
      {
      "id": "123","station": {
        "id": 5,"name": "Teststation"
      },"values": [
        {
          "id": "way","values": [ 339,340,341 ]
        },{
          "id": "time","values": [ 1,2,3 ]
        },{
          "name": "element_1","type": "line","result": "nok"
        },{
          "name": "element_2","type": "rect",{
          "name": "element_3","result": "ok"
        }
      ]
    }
  ];

function addColor(myArray) {
    const x =  myArray.map(obj => {

      for (const prop in obj) {
        if (obj.hasOwnProperty(prop) && Array.isArray(obj[prop])) {
          for (const item in obj[prop]) {
            if (obj[prop][item].hasOwnProperty('result') && (obj[prop][item].type === 'line')) {
              obj[prop][item].result === 'nok' ? obj[prop][item].line = { color: 'red' } : obj[prop][item].line = { color: 'green' };
          } else if (obj[prop][item].hasOwnProperty('result') && (obj[prop][item].type === 'rect')) {
              obj[prop][item].opacity = 0.2;
              obj[prop][item].line = { color: 'gray',width: 0 };
              obj[prop][item].result === 'nok' ? (obj[prop][item].fillcolor = 'red') : (obj[prop][item].fillcolor = 'green');
          }
          }
        }
    }

    return obj; //<---- Check here
  });

  return x;
 }

 addColor(myArray);

解决方法

来自上方的评论:我认为您是错误的bcl-data$Name。尽管bcl-data.csv是您加载的文件,但已将其另存为对象bcl-意味着它应该只是bcl$NameselectInput(inputId = "typeInput",label = "Name",choices = bcl$Name)在过滤器中,您也可以简单地拥有filter(Name ==,因为您已经通过管道提供了bcl数据/对象。

为确保我们删除重复的值,我们可以添加unique

这是我认为应该起作用的(无法测试,因为没有数据)。

library(shiny)
library(tidyverse)
library(shinythemes)
library(ggplot2)
library(dplyr)



bcl <- read.csv("bcl-data.csv",stringsAsFactors = FALSE)



# Define UI for application that draws a histogram
ui <- fluidPage(theme = shinytheme("darkly"),# Application title
titlePanel("Overzicht S&P 500 Aandelen"),# Sidebar with a slider input for number of bins 
sidebarLayout(
sidebarPanel(
sliderInput(inputId = "priceInput",label = "close",min = 0,max = 2050,value = c(0,300),pre = "$"),selectInput(inputId = "typeInput",choices = unique(bcl$Name)),dateRangeInput(inputId = "dateInput",label = "date",start = "2013/02/08",end = "2013/03/08",format = "yy/mm/dd")
),# Show a plot of the generated distribution
mainPanel(
tabsetPanel(
tabPanel("Plot",plotOutput("Plot")),tabPanel("Datatable",tableOutput("Datatable"))
            )
        )
    )
)



# Define server logic required to draw a histogram
server <- function(input,output) { 
    output$Plot <- renderPlot({ 
        filtered <- bcl %>%
            filter(close >= input$priceInput[1]) %>%
            filter(close <= input$priceInput[2]) %>%
            filter(date >= input$dateInput[1] & date <= input$dateInput[2]) %>%
            filter(Name == input$typeInput)
        filtered
        ggplot(filtered,aes(x = date,y = close,color = Name)) +
            geom_point()
    })
    output$Datatable <- renderTable({
        filtered <-
            bcl %>%
            filter(close >= input$priceInput[1]) %>%
            filter(close <= input$priceInput[2]) %>%
            filter(date >= input$dateInput[1] & date <= input$dateInput[2]) %>%
            filter(Name == input$typeInput)
        filtered
    })
}



# Run the application 
shinyApp(ui = ui,server = server)

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

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?