Блестящие и CSV файлы - PullRequest
       4

Блестящие и CSV файлы

0 голосов
/ 15 февраля 2019

Я очень новичок в программировании и смотрю видео о том, как создавать Shiny Apps через R Studio.

Одна вещь, которую я пытаюсь найти, - это простой код, который я могу использовать, который просит Shiny выбратьCSV-файл, который находится на моем рабочем столе.

Можно ли этого достичь или мне нужно сначала загрузить набор данных в R Studio?

Я не уверен, что запутываюсь и должен простовместо этого используется функция read / fileInput

Все справочные руководства показывают этот код:

fileInput("file1", "Choose CSV File",
        accept = c(
          "text/csv")

Так что мне просто заменить "text / csv" своим собственным путем?

Я очень запутался в противоречивой информации и надеюсь, что кто-то может объяснить мне это с точки зрения непрофессионала

Заранее спасибо

1 Ответ

0 голосов
/ 20 февраля 2019

Попробуйте и отправьте отзыв.

library(shiny)
library(ggplot2)
#ui.R
ui <- fluidPage(
  titlePanel("My shiny app"), sidebarLayout(
sidebarPanel(
  helpText("This app shows how a user can upload a csv file. Then, plot the data.
          Any file can be uploaded but analysis is only available
          if the data is in same format as the sample file, downloadable below
          "),
  a("Data to be plotted", href="https://www.dropbox.com/s/t3q2eayogbe0bgl/shiny_data.csv?dl=0"),
  tags$hr(),
  fileInput("file","Upload the file"), 
  h5(helpText("Select the read.table parameters below")),
  checkboxInput(inputId = 'header', label = 'Header', value = TRUE),
  checkboxInput(inputId = "stringAsFactors", "stringAsFactors", FALSE),
  br(),
  radioButtons(inputId = 'sep', label = 'Separator', choices = c(Comma=',',Semicolon=';',Tab='\t', Space=''), selected = ',')
),
mainPanel(
  uiOutput("tb"),
  plotOutput("line")             
)
)
)

#server.R
server <- function(input,output){
data <- reactive({


file1 <- input$file
if(is.null(file1)){return()} 

read.table(file=file1$datapath, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)})

output$filedf <- renderTable({
if(is.null(data())){return ()}
input$file
}) 

output$sum <- renderTable({
if(is.null(data())){return ()}
summary(data())
})

output$table <- renderTable({
if(is.null(data())){return ()}
data()
})

output$line <- renderPlot({
if (is.null(data())) { return() }
print(ggplot(data(), aes(x=date, y=aa)) + geom_line()+ facet_wrap(~station)) })

output$tb <- renderUI({if(is.null(data()))
h5()               
else
  tabsetPanel(tabPanel("About file", tableOutput("filedf")),tabPanel("Data", tableOutput("table")),tabPanel("Summary", tableOutput("sum")))
})
}


shinyApp(ui = ui, server = server)

enter image description here

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...