[英]Converting Outputs to Inputs in R Shiny
I was trying to get the list of files in a location based on user selected date and supply that list as options (maybe with checkbox) to select a file and show that as output in R Shiny. I was trying to get the list of files in a location based on user selected date and supply that list as options (maybe with checkbox) to select a file and show that as output in R Shiny. I could get to the point where I get the list, but unable to supply this to user as for option to make a selection and shpw the contents.我可以到达获得列表的地步,但无法将其提供给用户作为选择并显示内容的选项。 Any help is appreciated.任何帮助表示赞赏。
ui <- fluidPage(
titlePanel("Select the execution date"),
dateInput("ME_DATE",label=h3("Execution Date Input"), value="2020-05-29"),
hr(),
fluidRow(column(3,verbatimTextOutput("Output_path"))),
h4("Files in Above Location"),
hr(),
verbatimTextOutput("Output_files")
)
server <- function(input, output) {
# Main Directory for Source Files
Copied_Source_Files_DIR <- "U:/Source Files/"
Copied_Source_Files_loc <- reactive({
year_N_ME_DATE <- format(input$ME_DATE,"%Y")
month_N_ME_DATE <- format(input$ME_DATE,"%m")
month_T_ME_DATE <- months(input$ME_DATE)
file.path(paste(Copied_Source_Files_DIR,year_N_ME_DATE,"/",month_N_ME_DATE,". ",month_T_ME_DATE,"/",sep=""))
})
output$Output_path <- renderPrint({ Copied_Source_Files_loc() })
# files
output$Output_files <- renderPrint(list.files(Copied_Source_Files_loc()))
}
shinyApp(ui, server)
Don't think of an output$
as a possible intermediate step, it is always a terminator in a sense.不要将output$
视为可能的中间步骤,它在某种意义上始终是终结者。 It is best that you keep data separate as reactive(.)
data, and use it in multiple places.最好将数据作为reactive(.)
数据分开,并在多个地方使用它。
filelist <- reactive({ list.files(Copied_Source_Files_loc()) })
output$Output_files <- renderPrint(filelist())
updateCheckboxInput' would be a way to deal with it (as r2evans suggested). This solution uses a
updateCheckboxInput' would be a way to deal with it (as r2evans suggested). This solution uses a
uiOutput` that allows you to generate the UI elements on the server side and send that to the UI. updateCheckboxInput' would be a way to deal with it (as r2evans suggested). This solution uses a
uiOutput`,允许您在服务器端生成 UI 元素并将其发送到 UI。 It does not require a reactive expression as step between input and output.它不需要反应式表达式作为输入和 output 之间的步骤。
ui <- fluidPage(
titlePanel("Select the execution date"),
dateInput("ME_DATE",label=h3("Execution Date Input"), value="2020-05-29"),
hr(),
fluidRow(column(3,verbatimTextOutput("Output_path"))),
h4("Files in Above Location"),
hr(),
uiOutput("Output_files")
)
server <- function(input, output) {
# Main Directory for Source Files
Copied_Source_Files_DIR <- "./"
Copied_Source_Files_loc <- reactive({
year_N_ME_DATE <- format(input$ME_DATE,"%Y")
month_N_ME_DATE <- format(input$ME_DATE,"%m")
month_T_ME_DATE <- months(input$ME_DATE)
file.path(paste(Copied_Source_Files_DIR,year_N_ME_DATE,"/",month_N_ME_DATE,". ",month_T_ME_DATE,"/",sep=""))
})
output$Output_path <- renderPrint({ Copied_Source_Files_loc() })
# files
output$Output_files <- renderUI({
checkboxGroupInput("File_Selector",
"Select a file",
choices = list.files(Copied_Source_Files_loc()))
})
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.