R 从excel工作表中获取数据,并将其作为下拉列表显示在应用程序中
我已经制作了一个闪亮的应用程序,在其中我提供了一个文件输入,用户可以像这样输入excel表格:“”。我设计了一个应用程序,看起来像这样:''。我的代码是:R 从excel工作表中获取数据,并将其作为下拉列表显示在应用程序中,r,shiny,R,Shiny,我已经制作了一个闪亮的应用程序,在其中我提供了一个文件输入,用户可以像这样输入excel表格:“”。我设计了一个应用程序,看起来像这样:''。我的代码是: library(shiny) library(readxl) library(tidyverse) ui <- fluidPage( fileInput("config","Load Configuration File",accept =c('.xls',',xlsx')), actionButton("show_field
library(shiny)
library(readxl)
library(tidyverse)
ui <- fluidPage(
fileInput("config","Load Configuration File",accept =c('.xls',',xlsx')),
actionButton("show_fields","Show Fields"),
actionButton("estimate","Estimate"),
uiOutput("ui"),
textOutput("prod")
)
server <- function(input,output) {
x <- reactive({read_excel(input$config$datapath)})
conf <- reactive({x() %>% column_to_rownames(., var = "Rows")})
design <- eventReactive(input$show_fields, {
fluidPage(
numericInput("size","Size",value = 0),
lapply(1:nrow(conf()),function(i) {
selectInput(row.names(conf())[i],label = row.names(conf())[i],choices = colnames(conf()))
})
)
})
output$ui <- renderUI({design()})
mul <- eventReactive(input$estimate, {
sapply(1:nrow(conf()), function(j) {
conf()[row.names(conf())[j],eval(parse(text = paste0("input$",row.names(conf())[j],sep = "")))]
})
})
output$prod <- renderText({paste("Product is: ",prod(mul(),na.rm = TRUE)*input$size)})
}
shinyApp(ui=ui,server = server)
库(闪亮)
图书馆(readxl)
图书馆(tidyverse)
用户界面