下面的代码从本地计算机获取一个 CSV 文件并将其显示在主面板上。不幸的是,代码没有运行,这意味着在选择“set1”、“set2”等选项时,它不会显示预期的 CSV 结果。我是 R Shiny 的新手。有人可以帮我解决问题吗?
library(here)
library(shiny)
set1_path <- here("set1.csv")
set2_path <-here("set2.csv")
set3_path <-here("set3.csv")
set4_path <- here("set4.csv")
set1<- read.csv(set1_path)
set2 <- read.csv(set2_path)
set3 <- read.csv(set3_path)
set4 <- read.csv(set4_path)
options(shiny.maxRequestSize=30*1024^2)
shinyApp(
ui = tagList(
navbarPage(
theme = "spacelab",
tabPanel("report extracting",
sidebarPanel(
fileInput("file1", "Select datasets:",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv"),
),
# tags$hr(),
# checkboxInput("header", "Header", TRUE),
# textInput("txt", "Study info:", "Study name read"),
# sliderInput("slider", "Tables to read:", 1, 100, 30),
# tags$h5("Prepare extraction"),
selectInput("pdfExtract1", "Pick a Domain", choices = c("domain1", "domain2", "domain3", "domain4")),
tableOutput("preview"),
actionButton("pdfExtract", "Extract", class = "btn-primary"),
# actionButton("dataset", "Extract", class = "btn-primary")
#Reading extracted datasets
# Input: Choose dataset ----
selectInput("dataset", "Choose a dataset:",
choices = c("SelectDataSet ", "set1", "set2", "set3", "set4")),
# Button
downloadButton("downloadData", "Download")
),
mainPanel(
tableOutput("table"),
# tableOutput("contents"),
tabsetPanel(
tabPanel("PDF File select",
h4("Domains"),
tableOutput("table"),
h3("Extracting..."),
# selectInput("pdfExtract1", "Pick a Domain", choices = c("domain1", "domain2", "domain3", "domain4")),
# tableOutput("preview"),
# actionButton("pdfExtract", "Extract", class = "btn-primary")
# downloadButton("download", "Download .tsv")
),
tabPanel("Raw data", "TBD"),
tabPanel("Summary data", "TBD")
)
)
), # end of first tabpanel
tabPanel("calculation",
sidebarPanel(
fileInput("file2", "Select datasets:",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv")
),
tags$hr(),
checkboxInput("header", "Header", TRUE),
textInput("txt2", "domain info:", "report"),
sliderInput("slider", "Tables to read:", 1, 100, 30),
tags$h5("calculation"),
actionButton("dataset2", "Extract", class = "btn-primary")
),
mainPanel(
tableOutput("contents2"),
tabsetPanel(
tabPanel("Datasets",
h4("Domains"),
tableOutput("table2"),
h3("Summarizing...")
)
)
)
),
tabPanel("study compare",
sidebarPanel(
fileInput("file3", "compare:"),
textInput("txt3", "Study info:", "Study name read"),
tags$h5("calculation"),
actionButton("action2", "Compare", class = "btn-primary")
),
mainPanel(
tabsetPanel(
tabPanel("PDF File select",
h4("Domains"),
tableOutput("table3"),
h3("Comparing..."),
),
tabPanel("Summary data", "TBD")
)
)
)
)
),
server = function(input, output,session) {
# output$contents <- renderTable({
# # input$file1 will be NULL initially. After the user selects
# # and uploads a file, it will be a data frame with 'name',
# # 'size', 'type', and 'datapath' columns. The 'datapath'
# # column will contain the local filenames where the data can
# # be found.
# inFile <- input$file1
#
# if (is.null(inFile))
# return(NULL)
#
# read.csv(inFile$datapath, header = input$header)
# })
# output$contents2 <- renderTable({
# # input$file1 will be NULL initially. After the user selects
# # and uploads a file, it will be a data frame with 'name',
# # 'size', 'type', and 'datapath' columns. The 'datapath'
# # column will contain the local filenames where the data can
# # be found.
# inFile <- input$file2
#
# if (is.null(inFile))
# return(NULL)
# read.csv(inFile$datapath, header = input$header)
# })
# output$txtout <- renderText({
# paste(input$txt, input$slider, format(input$date), sep = ", ")
# })
output$table <- renderTable({
df <- c("datasetsx")
})
output$table2 <- renderTable({
df <- c("datasetsy")
})
output$table3 <- renderTable({
df <- c("datasetsz")
})
observeEvent(input$dataset, {
source("domain.R", local = TRUE)
})
observeEvent(input$dataset2, {
source("calculation.R", local = TRUE)
})
#Domain level Selection
observeEvent(input$pdfExtract, {
if(input$pdfExtract1 == "PP"){
source("domain1.R", local = TRUE)
}
else if(input$pdfExtract1 == "MA"){
source("domain2.R", local = TRUE)
}
else if (input$pdfExtract1 =="CL"){
source("domain3.R", local =TRUE)
}
else{
source("domain4.R", local =TRUE)
}
})
# Reactive value for selected dataset ----
datasetInput <- reactive({
switch(input$dataset,
"set1" = set2,
"set2" = set2,
"set3" = set3,
"set4" = set4)
})
# Table of selected dataset ----
output$table <- renderTable({
datasetInput()
})
# Downloadable csv of selected dataset ----
output$downloadData <- downloadHandler(
filename = function() {
paste(input$dataset, ".csv", sep = "")
},
content = function(file) {
write.csv(datasetInput(), file, row.names = FALSE)
}
)
}
)