【发布时间】:2021-01-05 06:54:56
【问题描述】:
我有以下应用程序来上传和显示数据文件:
library(shiny)
library(DT)
library(leaflet)
ui <- fluidPage(
titlePanel('SNP_Review'),
sidebarLayout(
sidebarPanel(
fileInput('target_upload', 'Choose file to upload', accept = c(
'text/csv',
'text/comma-separated-values',
'.csv'
)),
),
mainPanel(
tabsetPanel(
type = "tabs",
tabPanel('Samples_table', DT::dataTableOutput("sample_table")),
tabPanel('Samples_map', leafletOutput("sample_map"))
)
)
)
)
server <- function(input, output) {
df_products_upload <- reactive({
inFile <- input$target_upload
if (is.null(inFile))
return(NULL)
df <- read.csv(inFile$datapath, header = TRUE,sep = input$separator)
return(df)
})
output$sample_table <- DT::renderDataTable({
df <- df_products_upload()
DT::datatable(df)
})
table_data <- reactive({
})
output$sample_map <- renderLeaflet({
leaflet(data = table_data()) %>%
addProviderTiles(providers$OpenStreetMap.DE) %>%
addMarkers(lng = ~Longitude, lat = ~Latitude)
})
}
shinyApp(ui = ui, server = server)
它在表格中打印出我的数据。在下一步中,我想在带有传单的地图上显示表格的 GPS 数据。如何在表输出后定义响应式 table_data() 函数以使用地图中的数据以及可能的进一步操作?该表如下所示:
Name_ID Population Latitude Longitude
2 F6537_S01 Finland 60,745411 25,468228
3 N0484_S13 Norway 59,480365 7,920383
4 N0485_S25 Norway 60,925393 10,61182
5 N0486_S37 Norway 62,903547 9,824941
6 N0487_S49 Norway 61,78245 11,918215
提前致谢!
【问题讨论】:
-
你把
table_data <- reactive({df_products_upload()})放进去不行吗? -
问题:此文件中的上传数据不是数字(“333”),我希望我可以参考输出,因为应用程序完成后上传源应该是另一个...
-
啊,所以问题是将数据转换为正确的格式以使传单工作?您应该使用
dput(df)共享数据样本,而不仅仅是当前问题中的文本版本。