【发布时间】:2017-09-16 05:13:52
【问题描述】:
由于没有 JavaScript 和 API 方面的编程知识,我很难使这个示例满足我的需求:select GitHub repo。 我正在尝试使其适应此 API:https://api-adresse.data.gouv.fr/search/? .
响应是一个 GeoJSON 文件,其中的特征存储在 response$features 中。我想获取每个功能的 properties$label 属性。
这是我到目前为止所做的。我得到一个数组,但项目没有显示在下拉列表中...
用户界面:
########
# ui.R #
########
library(shiny)
fluidPage(
title = 'Selectize examples',
mainPanel(
selectizeInput('addresses', 'Select address', choices = '', options = list(
valueField = 'properties.label',
labelField = 'properties.label',
searchField = 'properties.label',
options = list(),
create = FALSE,
render = I("
{
option: function(item, escape) {
return '<div>' + '<strong>' + escape(item.properties.name) + '</strong>' + '</div>';
}
}" ),
load = I("
function(query, callback) {
if (!query.length) return callback();
$.ajax({
url: 'https://api-adresse.data.gouv.fr/search/?',
type: 'GET',
data: {
q: query
},
dataType: 'json',
error: function() {
callback();
},
success: function(res) {
console.log(res.features);
callback(res.features);
}
});
}"
)
))
)
)
服务器:
############
# server.R #
############
library(shiny)
function(input, output) {
output$github <- renderText({
paste('You selected', if (input$github == '') 'nothing' else input$github,
'in the Github example.')
})
}
感谢您的帮助。
【问题讨论】:
标签: r shiny selectize.js