我希望你的第一个闪亮的应用程序,
实际上我想在用户更改选择输入时在侧栏面板上添加一些更改 .
例如,对于我的以下代码:
当用户选择choice3时,我想要闪亮的显示4文件输入,使用户能够添加4个文件,当用户选择复杂或super_complex时,默认将是2个文件输入,
我怎么能在R中应用它?
Ui.R
library(shiny)
library(shinythemes)
library(readxl)
library(dplyr)
options(error = traceback)
shinyUI(fluidPage(
theme=shinytheme("flatly"),
themeSelector(),
navbarPage(
title="My shiny App",
id="nav"),
sidebarLayout(
sidebarPanel(
selectInput(
"TFType",
"Select one of the following" ,
c("complex calc"="complex", "super complex calc"="super_complex" , "choice3")
),
# tags$hr(),
fileInput(
"file1" ,
tableOutput("inputType"),
multiple = FALSE
),
# tags$hr(),
fileInput(
"file2" ,
tableOutput("inputType2"),
multiple = FALSE
),
verbatimTextOutput(" output$choice3"),
# numericInput("obs", "Number of observations to view:", 10),
actionButton("act" , "Calculate"),
downloadButton("downloadData", "Download")
),
mainPanel(tabsetPanel(
tabPanel("Data", DT::dataTableOutput("contents") , tableOutput("view"))
,
tabPanel("Summary Data",DT::dataTableOutput("complex_calc")),
tabPanel("plots" , verbatimTextOutput("datadownload"))
))
)
))
Server.R
server <- function(input, output) {
options(shiny.maxRequestSize = 200*1024^2)
df <- reactive({
req(input$file1)
tryCatch({
df <- readxl::read_xlsx(input$file1$datapath, 1)
},
error = function(e) {
stop(safeError(e))
})
})
df_CBU <- reactive({
req(input$file2)
tryCatch({
df_CBU <- readxl::read_xlsx(input$file2$datapath, 1)
},
error = function(e) {
stop(safeError(e))
})
})
output$contents <- DT::renderDataTable({
df()
})
output$summary <- renderPrint({
summary(input$file1 , as.numeric(input$file1))
})
calcuation <- eventReactive(input$act, {
if (input$TFType == "complex") {
complex_calc2(df(),df_CBU())
}
else if (input$TFType == "super_complex") {
complex_calc3(df(),df_CBU())
}
else if (input$TFType == "choice3") {
complex_calc4(df(),df_CBU())
}
})
output$complex_calc <- DT::renderDataTable({
calcuation()
})
output$downloadData <- downloadHandler(
filename = function() {
paste(input$file1, ".csv", sep = "")
},
content = function(file) {
write.csv(calcuation(), file, row.names = FALSE )
}
)
output$inputType <- renderText( {
if ( input$TFType == "complex")
"Upload File1"
else if ( input$TFType == "super_complex")
"Upload File2"
else if ( input$TFType == "choice3")
"Upload Mapping Files"
})
output$inputType2 <- renderText( {
if ( input$TFType == "complex")
"Upload File3"
else if ( input$TFType == "super_complex")
"Upload FileFile2"
})
# output$choice3 <- renderUI ( {
# if (input$TFType == "choice3") {
# fileInput(
# "file3" ,
# tableOutput("inputType"),
# multiple = FALSE
# )
# tags$hr(),
# fileInput(
# "file4" ,
# tableOutput("inputType2"),
# multiple = FALSE
# )
# }
# })
}
提前致谢