如何从闪亮的输入操作表/数据框?

时间:2019-06-05 09:24:38

标签: r shiny

我在光泽方面还很陌生,并且在光泽的反应对象和数据帧中挣扎。

我想制作一个允许用户加载文件(如.csv,.rds等)的应用程序,该文件将成为之后所有过程的“基础”。想法是,一旦文件被上传,一些面板将显示上传表的子集或基于上传表进行计算的新表。

实际上,困难在于合奏,特别是如何从表中选择行和列。我正在搜索闪亮的df [c(1,2),]或df [,c(1,2)]或df $ variable_name的等效项。

这是我的代码,我只想显示输入文件的第一和第二列,以查看我完成的处理是否正常:

## Only run examples in interactive R sessions

library(sas7bdat)


ui <-fluidPage(navlistPanel(
  tabPanel("Welcome",textOutput("welcome_message"),textOutput("welcome_message_2"),img(src="logo_danone.jpg", height = 350, width = 350)),

  tabPanel("Input files", fileInput("file1", "Choose File",
                                    accept = c(
                                      "text/csv",
                                      "text/comma-separated-values,text/plain",
                                      ".csv")),
           inputPanel(
             tableOutput("contents")

           )),

  tabPanel("AUC Derivation",tableOutput("selection")),

  tabPanel("AUC Derivation plots"),

  tabPanel("Shape Analysis"),

  tabPanel("Tables"),

  tabPanel("Plots"),

  tabPanel("Clustering"),

  tabPanel("tab1",dataTableOutput("value")),

  tabPanel("tab2",plotOutput("hist"))






))

server <-function(input, output) {

  # You can access the value of the widget with input$file, e.g.

  output$welcome_message <- renderText("test")
  output$welcome_message_2 <- renderText("logo")

  output$value <- renderDataTable({
    iris
  })

  output$contents <- renderTable({
    # input$file1 will be NULL initially. After the user selects
    # and uploads a file, it will be a data frame with 'name',
    # 'size', 'type', and 'datapath' columns. The 'datapath'
    # column will contain the local filenames where the data can
    # be found.
    inFile <- input$file1

    if (is.null(inFile))
      return(NULL)

    readRDS(inFile$datapath)
  })

  output$selection <- reactive({return(input$file1[,c(1,2)])})

  #output$selected <- renderTable({selection()})

  output$hist <- renderPlot({     # Refers  to putputs with output$<id>
    ggplot2::ggplot(data = iris, aes(y = Sepal.Length)) + geom_boxplot() # Refers to inputs with input$<id>
  })

}

  shinyApp(ui, server)
#}

有人能解释我如何通过闪亮的方式操纵上传的表格吗?

预先感谢

1 个答案:

答案 0 :(得分:0)

@denis:这是.csv csv file

的可复制示例

我想知道的是如何对输入的csv(它是一个数据帧)进行操作和子集化,因为我将不得不通过已编写的函数过滤,合并和使用列,并在不同的面板中显示结果

 ## Only run examples in interactive R sessions

library(sas7bdat)


ui <-fluidPage(navlistPanel(
  tabPanel("Welcome",textOutput("welcome_message"),textOutput("welcome_message_2"),img(src="logo_danone.jpg", height = 350, width = 350)),

  tabPanel("Input files", fileInput("file1", "Choose File",
                                    accept = c(
                                      "text/csv",
                                      "text/comma-separated-values,text/plain",
                                      ".csv")),
           inputPanel(
             tableOutput("contents")

           )),

  tabPanel("AUC Derivation",tableOutput("selection")),

  tabPanel("AUC Derivation plots"),

  tabPanel("Shape Analysis"),

  tabPanel("Tables"),

  tabPanel("Plots"),

  tabPanel("Clustering"),

  tabPanel("tab1",dataTableOutput("value")),

  tabPanel("tab2",plotOutput("hist"))






))

server <-function(input, output) {

  # You can access the value of the widget with input$file, e.g.

  output$welcome_message <- renderText("test")
  output$welcome_message_2 <- renderText("logo")

  output$value <- renderDataTable({
    iris
  })

  output$contents <- renderTable({
    # input$file1 will be NULL initially. After the user selects
    # and uploads a file, it will be a data frame with 'name',
    # 'size', 'type', and 'datapath' columns. The 'datapath'
    # column will contain the local filenames where the data can
    # be found.
    inFile <- input$file1

    if (is.null(inFile))
      return(NULL)

    read.csv(inFile$datapath, sep = ";")
  })

  output$selection <- reactive({return(input$file1[,c(1,2)])})

  #output$selected <- renderTable({selection()})

  test <- reactive({input$file1()})

  output$hist <- renderPlot({     # Refers  to putputs with output$<id>
    ggplot2::ggplot(data = iris, aes(y = Sepal.Length)) + geom_boxplot() # Refers to inputs with input$<id>
  })

}

  shinyApp(ui, server)
#}