Как манипулировать таблицами / dataframe от ввода в году? - PullRequest
0 голосов
/ 05 июня 2019

Я совершенно новый в блестящем, и я борюсь с реактивными объектами и кадром данных в блестящем.

Я хотел бы создать приложение, которое позволит пользователю загружать файл (например, .csv, .rds и т. Д.), Который будет «основой» всего процесса после.Идея состоит в том, что после загрузки файла некоторые панели будут отображать подмножества загруженной таблицы или новые таблицы, сделанные на основе вычислений на основе загруженной таблицы.

На самом деле сложность заключается в синтаксисе, особенно в том, как выбирать строки и столбцы из таблицы.Я ищу эквивалент df [c (1,2),] или df [, c (1,2)] или df $ variable_name в блестящем.

Вот мой код, я просто хочучтобы отобразить 1-й и 2-й столбцы входного файла, чтобы увидеть, в порядке ли обработанная мною обработка:

## 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 голосов
/ 05 июня 2019

@ 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)
#}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...