【问题标题】:Adjust fileinput in Shiny在 Shiny 中调整文件输入
【发布时间】:2021-08-09 03:48:49
【问题描述】:

我插入了一个df 数据库作为示例供您查看它的外观,但我想从fileInput 加载这个df 数据库,也就是说,这个数据库将采用“xlsx”格式并且我将通过fileInput 加载。你能帮我调整一下吗?

非常感谢!

library(shiny)
library(shinythemes)

function.cl<-function(df,date,d1,d2){
  
  df <- structure(
   list(date = c("2021-01-01","2021-01-02","2021-01-03","2021-01-04","2021-01-05"),
         d1 = c(0,1,4,5,6), d2 = c(2,4,5,6,7)),class = "data.frame", row.names = c(NA, -5L))
}    
ui <- fluidPage(
  
  ui <- shiny::navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
                          br(),
                          
                          tabPanel("",
                                   fileInput("file", "Please upload a file"),
                                   sidebarLayout(
                                     sidebarPanel(
                                       
                                       selectInput("date", label = h4("Date"),""),
                                       selectInput("d1", label = h4("D1"),""),
                                       selectInput("d2", label = h4("D2"),""),
                                       br(),
                                       actionButton("reset", "Reset"),
                                     ),
                                     
                                     mainPanel(
                                     ))
                          )))


server <- function(input, output,session) {
  data <- reactive(function.cl())
  
  observe({
    updateSelectInput(session, "date", label = "Date", unique(data()$date))
    updateSelectInput(session, "d1", label = "D1", unique(data()$d1))
    updateSelectInput(session, "d2", label = "D2", unique(data()$d2))
  })
  
}

shinyApp(ui = ui, server = server)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    你可以试试这个

    data <- eventReactive(input$file, {
        if (is.null(input$file)) return(NULL)
        df <- read_excel(input$file$datapath)
        df
      })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-30
      • 2018-05-25
      • 1970-01-01
      • 2020-06-27
      • 1970-01-01
      • 2020-10-21
      • 2021-05-08
      相关资源
      最近更新 更多