2017-10-11 3 views
1

私はウェブサイトからデータを取得している問題を説明する簡単な光沢のあるアプリを書いています。ここではUIのコードは次のとおりです。URLを介してデータを取得する光沢のあるアプリは、ローカルでは動作しますが、shinyapps.ioでは動作しません。

library(shiny) 

shinyUI(fluidPage(

# Application title 
titlePanel("Test App"), 

# Sidebar with slider inputs 
sidebarLayout(
    sidebarPanel(
     actionButton("button", "Fetch Data") 
       ), 


    mainPanel(
     tabsetPanel(
      tabPanel("Data", textOutput("crimelist")) 
     ) 
    ) 
) 
) 
) 

そしてここでは、サーバーのコードは次のとおりです。

library(shiny) 

# Define server logic 
shinyServer(function(input, output, session) { 

    # Get a list of the different types of crime 
    observeEvent(input$button, { 
     url <- "https://phl.carto.com/api/v2/sql?format=csv&q=SELECT 
       distinct rtrim(text_general_code) as text_general_code 
          FROM incidents_part1_part2 
          order by text_general_code" 
    crimelist <- read.csv(url(url), stringsAsFactors = FALSE)$text_general_code 
    output$crimelist <- renderText({crimelist}) 
    }) 
}) 

フェッチされるデータはhttps://cityofphiladelphia.github.io/carto-api-explorer/#incidents_part1_part2で記述されています。

私のローカル環境でこの光沢のあるアプリを実行すると、完全に動作します。それをshinyapps.ioに公開して実行すると、ボタンをクリックしてデータを取得するとアプリケーションが失敗します。光沢のあるログでは、次のように報告されます

2017-10-11T14:46:31.242058+00:00 shinyapps[224106]: Warning in 
open.connection(file, "rt") : 
2017-10-11T14:46:31.242061+00:00 shinyapps[224106]: URL 'https://phl.carto.com/api/v2/sql?format=csv&q=SELECT distinct 
rtrim(text_general_code) as text_general_code 
2017-10-11T14:46:31.242062+00:00 shinyapps[224106]: FROM incidents_part1_part2 
2017-10-11T14:46:31.242063+00:00 shinyapps[224106]: order by text_general_code': status was 'URL using bad/illegal format or missing URL' 
2017-10-11T14:46:31.243062+00:00 shinyapps[224106]: Warning: Error in open.connection: cannot open connection 

私は本当に困惑しています - これはいくつかの種類の光沢のあるサーバーの問題ですか?そこに誰かが手がかりを持っているなら、私はすべての耳です!

答えて

1

私はGoogleのグループが私の問題を解決しShinyapps.ioのユーザーに複数のボードでこの質問を投稿し、ヨシュアスピーバック:

をあなたはそれが有効になるようにするためにURLをエンコードする必要があり、例えばhttps://phl.carto.com/api/v2/sql?format=csv&q=SELECT%20distinct%20rtrim(text_general_code)%20as%20text_general_code%20FROM%20incidents_part1_part2%20order%20by%20text_general_code

shinyapps.ioがLinux上で動作するため、curlがこのURLを取得するために使用されている可能性があります。私の推測では、ローカルでWindowsを使用しています。これは、URLにある空白と改行を許容する、それほど厳格ではないメカニズムを使用しています。

提案された変更を行った後、現在は期待どおりに動作します。ありがとう、ジョシュア!

関連する問題