У меня есть код с navbarPage, который пользователь выбирает, какой тест он хочет, загружает свой файл, выбирает параметры и загружает результаты.
Моя проблема: как мне организовать свой код, чтобы знать, какойпротестировать выбранного пользователя?Чтобы мой код работал, как он просил?
Когда у меня был только один fileInput, мой код работал правильно, но когда я добавил второй, перестал показывать мои данные в виде таблицы на главной странице, и моя кнопка download сошла с ума.
Мой код:
ui <- navbarPage(title = "DadosFacil", fluid = TRUE, theme = shinytheme("cosmo"),
#---- TABA DE NORMALIDADE
tabPanel("Normalidade", id = "NormalTab",
sidebarLayout(
sidebarPanel(
helper("",
colour = "black",
type = "inline",
title = "Upload do arquivo",
size = "s",
content = "Selecione apenas um arquivo em documento de texto (.txt), para mais informacoes sobre como organizar seu arquivo acesse nosso faq."),
fileInput("file1", "Escolha seus dados em .txt", #Ill only accept .txt files
accept =".txt"),
helper("",
colour = "black",
type = "inline",
title = "Ajuda",
size = "s",
content = "Marque se seu arquivo possui os nomes das variaveis na primeira linha"),
checkboxInput("header", "Header",value = TRUE),
helper("",
colour = "black",
type = "inline",
title = "Separador Decimal",
size = "s",
content = "Selecione como voce separou seus numeros no seu arquivo, comumente no Brasil se utiliza a virgula, nos outros paises o ponto. Note que caso selecione errado, obtera um erro."),
radioButtons("decimal", "Ponto ou Virgula: ",
choices = c(Virgula = ",", Ponto = "."),
selected = ","),
tags$hr(), #Linha horizontal
downloadButton("downloadData", "Download")
),
mainPanel(
dataTableOutput("Previa")
)
)
),
#---ABA DA ANOVA
navbarMenu("ANOVA",
#---DELINEAMENTO INTEIRAMEINTE CASUALIZADO
tabPanel("DIC", id = "DicTab",
sidebarLayout(
sidebarPanel(
helper("",
colour = "black",
type = "inline",
title = "Upload do arquivo",
size = "s",
content = "Selecione apenas um arquivo em documento de texto (.txt), para mais informacoes sobre como organizar seu arquivo acesse nosso faq."),
fileInput("file2", "Escolha seus dados em .txt -> DIC", #Ill only accept .txt files
accept =".txt"),
helper("",
colour = "black",
type = "inline",
title = "Ajuda",
size = "s",
content = "Marque se seu arquivo possui os nomes das variaveis na primeira linha"),
checkboxInput("header", "Header",value = TRUE),
helper("",
colour = "black",
type = "inline",
title = "Separador Decimal",
size = "s",
content = "Selecione como voce separou seus numeros no seu arquivo, comumente no Brasil se utiliza a virgula, nos outros paises o ponto. Note que caso selecione errado, obtera um erro."),
radioButtons("decimal", "Ponto ou Virgula: ",
choices = c(Virgula = ",", Ponto = "."),
selected = ","),
tags$hr(), #Linha horizontal
downloadButton("downloadData", "Download")
),
mainPanel(
dataTableOutput("Previa")
)
)
),
tabPanel("DBC",
sidebarLayout(
sidebarPanel(
),
mainPanel(
)
)
),
tabPanel("DQL",
sidebarLayout(
sidebarPanel(
),
mainPanel(
)
)
)
)
)
server <- function(input, output, session) {
observe_helpers()
datasetInputNormal <-reactive({
req(input$file1)
tryCatch({
df <- read.table(input$file1$datapath,
header = input$header,
sep = "\t",
dec = input$decimal)
},
error = function(e){
#Retorna error se der algum problema
stop(safeError(e))
})
return(df)
})
datasetInputDic <-reactive({
req(input$file2)
tryCatch({
df <- read.table(input$file2$datapath,
header = input$header,
sep = "\t",
dec = input$decimal)
},
error = function(e){
#Retorna error se der algum problema
stop(safeError(e))
})
return(df)
})
output$Previa <- DT::renderDataTable(DT::datatable(datasetInput()))
output$NormalidadeDownload <- downloadHandler(
filename = function(){
paste("Resul_",input$file1$name, sep = "")
},
content = function(file){
if(input$id == "NormalTab"){
writeLines(VariosNormal(datasetInputNormal()), con = file, sep = "" ) #Call my function VariosNormal()
} else if(input$id == "DicTab"){
writeLines(Teste_DIC(datasetInputDic()), con = file, sep = "" ) #Call my function Teste_DIC()
}
}
)
}
shinyApp(ui, server)