R Shiny应用程序可以接受手动以及自动下拉菜单

时间:2019-05-06 06:12:01

标签: r shiny

我已经在R中创建了以下数据框

  ###IMPORT LIBRARIES
  library(shiny)
  library(shinyjs)
  library(shinydashboard)
  library(shinydashboardPlus)
  library(readxl)
  library(readr)
  library(WriteXLS)



   DF1<-data.frame("SlNo"=c(1:5), "X"=c(1:5), "Y"=c(1:5))
   ### WRITE TO EXCEL
   write.xlsx(x = DF1, file = "DF1.xlsx")

接下来,我创建了一个Shiny App,如下所示,可以从DF1中读取

   ui <- dashboardPage(
   dashboardHeader(title = "Tool", titleWidth = "300"),
   dashboardSidebar(width = '300', fluidRow(
   div(fileInput(inputId = "file", label = "Load Excel", multiple = T, 
   accept = c(".xlsx", ".csv", '.xls'))),
    div(htmlOutput(outputId =  "Mean1")

      ))),
      dashboardBody(  plotlyOutput(outputId = "Plot1") 
      ))



     server <- function(input, output) { 

    ############

   datasetInput <- reactive({

    infile<- input$file
    if (is.null(infile))
     return(NULL)

    ########CHANGE DATA TYPE HERE- EXCEL/CSV

    #data <- read.csv(file=infile$datapath)
    DF1<-read_excel(infile$datapath)

      list1<-mean(DF1$X)
     return(list1)
      })

    ####### WE NOW DISPLAY THE VALUES IN THE MENU BOXES

    output$Mean1<-renderUI({
    list1<-datasetInput()
    prod_2 <- list1
   selectInput(inputId = 'Mean1', label = 'Mean1', choices = prod_2, multiple 
   = TRUE, selectize = TRUE, selected = NULL)

      })

    Mean1 <- reactive({
    if(is.null(input$Mean1) || length(input$Mean1)==0)
    return()
    input$Mean1
     })
     }

      ###############RUN APP
    shinyApp(ui, server)

该应用取自DF1的X列的平均值,并在该应用的下拉列表中将其作为输入呈现。是否可以修改APP,使其除了显示的值外,还允许手动输入下拉菜单。目前仅接受自动生成的下拉值

0 个答案:

没有答案