使用闪亮的Web应用程序生成动态图形

时间:2018-05-17 12:39:02

标签: javascript java html css jsp

我对R的Shiny网络应用程序非常新。我想使用闪亮的网络应用程序生成动态图形。我浏览了CSV文件,当我浏览它时,该文件的动态列将出现在selectInput中。我放了两个selectInput X和Y.因此,如果用户从X轴和Y轴选择该列,那么将根据selectInput的选择动态生成图形。我上传了我的两个文件ui.r和server.r。如果我做错了请评论。如果有人回复我,那对我来说非常有益。     在这里输入代码

   ui.r


     library(shiny)
     library(shinythemes)


       shinyUI(fluidPage(
       theme = shinytheme("cyborg"),
       themeSelector(),
       titlePanel("Data Analytics and Visualization Dashboard"),
       sidebarLayout(
       sidebarPanel(
          fileInput('datafile', 'Choose CSV file', 
          accept=c('text/csv','text/comma-separated-values,text/plain')),  
          h5("Max file size to upload is 5 MB."),
          radioButtons("sep", "Seperator", choices = c(Comma = ',', semicolon = 
         ';', tab = "\t", space = " " )),
        br(),
        h4("Select columns from CSV"),
        uiOutput("toCol"),

         br(),
         h4("Select columns from CSV to plot"),
         uiOutput("selectX"),
         uiOutput("selectY")


         ),
         mainPanel(
         numericInput("obs", "Enter the number of rows to display:", 5),
         tableOutput("input_file"),
         h4("Summary"),
         verbatimTextOutput("sum"),
         plotOutput("p"),
         plotOutput("plot")
        )
        )
         ))

      server.r



     library(shiny)

      shinyServer(function(input, output,session) {


      #This function is repsonsible for reading a csv file
      filedata <- reactive({
       req(input$datafile)
       infile <- input$datafile
        if (is.null(infile)) {
         # User has not uploaded a file yet
          return(NULL)
        }
         read.csv(infile$datapath,nrows = input$obs, sep = input$sep)
        })

        output$input_file <- renderTable({
         filedata()
       })

        #The following set of functions populate the column selectors
       output$toCol <- renderUI({
        df <- filedata()
         if (is.null(df)) return(NULL)
         items=names(df)
         names(items)=items
         checkboxGroupInput("to", "Columns",items)
       })

       output$sum <- renderPrint({
        req(input$to)
        data <- filedata()
        print(summary(data[,input$to]))
      })


      output$selectX <- renderUI({
      df <- filedata()
       if (is.null(df)) return(NULL)
       items=names(df)
        names(items)=items
       selectInput("x", "Select X-axis:",items)
      })

     output$selectY <- renderUI({
      df <- filedata()
       if (is.null(df)) return(NULL)
       items=names(df)
        names(items)=items
        selectInput("y", "Select Y-axis:",items)
       })

      output$plot <- renderPlot({

       req(input$x)
       req(input$y)
        df <- filedata()
         plot(df,col="red",xlab="input$x",ylab="input$y",main="PLOT")


       })
      })

0 个答案:

没有答案