尝试将Excel CSV文件放入R Shinydashboard

时间:2018-07-25 16:34:09

标签: r shinydashboard

我已经使用Shinydashboard软件包在R中创建了主仪表板。但是,我的主要问题是如何将Excel Csv文件(包含所有数据)上载到仪表板?我一直在试图解决这个问题,但遇到了麻烦。到目前为止,我有以下脚本:

install.packages("shinydashboard")
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Analysis Project"),
  dashboardSidebar(
    menuItem("Dashboard", tabName = "dashboard"),
    menuItem("Filter Page"),
    menuItem("Data")
  ),
    dashboardBody(
      tabItems(
       tabItem(tabName = "dashboard")
)
)

)     服务器<-函数(输入,输出){}     ShinyApp(用户界面,服务器)

2 个答案:

答案 0 :(得分:0)

这种方式怎么样?

library(shiny)
library(readxl)

ui <- fluidPage(
  fileInput('file1', 'Insert File', accept = c(".xlsx")),
  textInput('file1sheet','Name of Sheet (Case-Sensitive)'),
  tableOutput("value")
)

server <- function(input, output) {

  sheets_name <- reactive({
    if (!is.null(input$file1)) {
      return(excel_sheets(path = input$file1$datapath))  
    } else {
      return(NULL)
    }
  })

  output$value <- renderTable({
    if (!is.null(input$file1) && 
        (input$file1sheet %in% sheets_name())) {
      return(read_excel(input$file1$datapath, 
                        sheet = input$file1sheet))
    } else {
      return(NULL)
    }
  })
}

shinyApp(ui, server)

答案 1 :(得分:0)

尝试编写这样的代码!

图书馆(闪亮)     库(shinydashboard)

 var authenticationContext = new AuthenticationContext(config);
    if (!config.popUp) {
        if (authenticationContext.isCallback(window.location.hash)) {
            authenticationContext.handleWindowCallback();
        }
    }
    var user = authenticationContext.getCachedUser();
    sessionStorage.setItem("adal:Tenant","@CommonMethods.GetAppConfigValue("ida:TenantId")")
    if (!user) {
        authenticationContext.login();
    }