R 循环中的反应式评估
我试图根据一些列表创建一些选项卡,并在这些选项卡中创建具有自己标识的类似字段。我们能创造和使用像这样的反动词吗R 循环中的反应式评估,r,shiny,R,Shiny,我试图根据一些列表创建一些选项卡,并在这些选项卡中创建具有自己标识的类似字段。我们能创造和使用像这样的反动词吗 eval(paste0("Updated_files_list_",Some_List[k], "()")) 我使用了以下代码和一个位置,但对于不同的选项卡,这将是不同的。似乎为列表创建了反应,但我无法为其赋值或调用它- Some_List <- list("AGG", "CMP1", "
eval(paste0("Updated_files_list_",Some_List[k], "()"))
我使用了以下代码和一个位置,但对于不同的选项卡,这将是不同的。似乎为列表创建了反应,但我无法为其赋值或调用它-
Some_List <- list("AGG", "CMP1", "CMP2")
Some_Long_List <- list("Aggregated Things", "Component 1", "Component 2")
sidebar <- dashboardSidebar(
do.call(sidebarMenu, c(lapply(1:length(Some_List), function(i) {
menuItem(Some_Long_List[i], tabName = paste0(Some_List[i],"_tab"))
}))))
uibody <- dashboardBody(
do.call(tabItems, c(lapply(1:length(Some_List), function(i) {
tabItem(tabName = paste0(Some_List[i],"_tab"), h2(Some_Long_List[i]),
fluidPage(fluidRow(column(3,
dateInput(paste0("ME_DATE_output_",Some_List[i]),label=h2("Select a Date"), value="2020-05-29"))
,column(9,column(verbatimTextOutput(paste0("file_path_",Some_List[i])),width=12),hr(),
selectInput(paste0('select_file_',Some_List[i]),'Select a File to display', choices=NULL),hr(),
column(dataTableOutput(paste0('selected_table_',Some_List[i])),width=12)))))
}))))
ui = dashboardPage(dashboardHeader(title = "Results"), sidebar, uibody)
server = function(input, output, session) {
# Location for Source Inputs
Some_loc <- "K:/Outputs"
lapply (1:length(Some_List), function(k){
ME_DATE_GUI <- reactive({input[[paste0("ME_DATE_output_",Some_List[k])]]})
# Files Path
output[[paste0("file_path_",Some_List[k])]] <- renderPrint({ req(Some_loc) })
# Updated Files list
assign(paste0("Updated_files_list_",Some_List[k]), reactive({
lf_some <- list.files(Some_loc,full.names = TRUE)
names(lf_some) <- basename(lf_some)
lf_some
}))
# Fetch selection of file
observeEvent(eval(paste0("Updated_files_list_",Some_List[k], "()")), {
updateSelectInput(session, paste0("select_file_",Some_List[k]), choices=eval(paste0("Updated_files_list_", Some_List[k],"()")))
})
# Display Selected file
output[[paste0("selected_table_",Some_List[k])]] <- renderDataTable({
req(input[[paste0("select_file_", Some_List[k])]])
read.csv(input[[paste0("select_file_", Some_List[k])]], header=T)
})
})
}
shinyApp(ui, server)
Some\u列出了为什么要使用eval()
和paste()
创建reactive?这似乎是一个不太理想的解决方案。通常,使用列表比操纵执行环境要好。您是否查看了reactiveValues()
列表?现在还不清楚你想做什么。如果您包含一个简单的示例输入和所需的输出,可以用来测试和验证可能的解决方案,那么就更容易为您提供帮助。@MrFlick,我已经用全部代码更新了这个问题。您能告诉我如何在这里使用reactiveValues()
吗。我只能想到循环,但那不起作用,所以我求助于lappy,但现在陷入了这个困境。