首页 > 解决方案 > 从 R Shiny 中的单个 .txt 文件调用多个变量

问题描述

我对 R 比较陌生,一直在研究我的前任开发的 R Shiny 应用程序。

我希望能够在当前代码行的末尾添加多个数字,以便一次从单个 .txt 文件中调用多个变量。当前的代码行是:

i <- as.numeric(input$zoneProject) + 3

这将调用 .txt 文件中的数字加 3。zoneProject 的值由用户选择,介于 1 和 18 之间。下面 .txt 文件示例中列出的前 3 个文件此时与应用程序无关,因此通过添加“+3”,它会跳过第 3 个。因此,如果选择了区域 1,它将是 1+3,它给出的值为 4,因此将选择与 .txt 文件中的数字 4 关联的栅格.

在与每个区域关联的 .txt 文件中列出了 11 个栅格,因此我希望能够一次调用与每个单独区域关联的所有栅格。因此,要在 .txt 文件的示例图片中调用区域 1 的栅格,它将是 + 3 和 21

Number|File|Name|Description    
1|n_1_forest.tif|lca_pres|LCA Present
2|hard_con1.tif|hard_con1|Areas with water, rock, littoral, mountain or urban land use
3|Nopeat.tif|non_peat_soils|non peat soils
4|All_Constraints_1.tif|All_Constraints_1|All Constraints for zone 1
5|All_Constraints_2.tif|All_Constraints_2|All Constraints for zone 2
6|All_Constraints_3.tif|All_Constraints_3|All Constraints for zone 3
7|All_Constraints_4.tif|All_Constraints_4|All Constraints for zone 4
8|All_Constraints_5.tif|All_Constraints_5|All Constraints for zone 5
9|All_Constraints_6.tif|All_Constraints_6|All Constraints for zone 6
10|All_Constraints_7.tif|All_Constraints_1|All Constraints for zone 7
11|All_Constraints_8.tif|All_Constraints_8|All Constraints for zone 8
12|All_Constraints_9.tif|All_Constraints_9|All Constraints for zone 9
13|All_Constraints_10.tif|All_Constraints_10|All Constraints for zone 10
14|All_Constraints_11.tif|All_Constraints_11|All Constraints for zone 11
15|All_Constraints_12.tif|All_Constraints_12|All Constraints for zone 12
16|All_Constraints_13.tif|All_Constraints_13|All Constraints for zone 13
17|All_Constraints_14.tif|All_Constraints_14|All Constraints for zone 14
18|All_Constraints_15.tif|All_Constraints_15|All Constraints for zone 15
19|All_Constraints_16.tif|All_Constraints_16|All Constraints for zone 16
20|All_Constraints_17.tif|All_Constraints_17|All Constraints for zone 17
21|All_Constraints_18.tif|All_Constraints_18|All Constraints for zone 18
22|dams24_100m_1.tif|dams24_100m_1|dams24_100m for zone 1
23|dams24_100m_2.tif|dams24_100m_2|dams24_100m for zone 2
24|dams24_100m_3.tif|dams24_100m_3|dams24_100m for zone 3
25|dams24_100m_4.tif|dams24_100m_4|dams24_100m for zone 4
26|dams24_100m_5.tif|dams24_100m_5|dams24_100m for zone 5
27|dams24_100m_6.tif|dams24_100m_6|dam

.txt 文件的数量最多为 183。

我希望一次从 .txt 文档中调用多个号码,但不确定如何将其写入原始代码。我确信这是基本的 R 知识,但是到目前为止我还没有让它工作。非常感谢任何帮助或想法,谢谢!

标签: rshiny

解决方案


推荐阅读