簡體   English   中英

閃亮的App R-清理和錯誤

[英]Shiny App R - Scrubbing and Error

我正在R中構建一個Shiny App,並且試圖清除有關用戶選擇的Pokemon的Web信息,但是在嘗試使用read_html()時,我始終遇到“錯誤:SLL證書問題”的問題。

ui:

  sidebarPanel( ui <- fluidPage( selectInput(inputId = "pokemon1", 'Choose a Pokémon:', c(Pokemon$Name)))), mainPanel( verbatimTextOutput("value")) 

然后是服務器:

 server <- function(input, output) { output$value <- renderPrint({ pokemon <- input$pokemon1 URLpokemon <- paste(c("https://bulbapedia.bulbagarden.net/wiki/", pokemon,"_(Pok%C3%A9mon)"), collapse="") # Read and parse HTML file pokemonSummary1 <- URLpokemon%>% read_html() %>% # R please help me read this HTML code html_nodes("p")%>% # type of HTML object .[[1]]%>% html_text() pokemonSummary2 <- URLpokemon%>% read_html() %>% # R please help me read this HTML code html_nodes("p")%>% # type of HTML object .[[2]]%>% html_text() pokemonSummary3 <- URLpokemon%>% read_html() %>% # R please help me read this HTML code html_nodes("p")%>% # type of HTML object .[[3]]%>% html_text() textAlmanac <- paste(c(pokemonSummary1,pokemonSummary2,pokemonSummary3), collapse=" ") paste(textAlmanac) }) 

我正在使用此數據集: https : //gist.github.com/armgilles/194bcff35001e7eb53a2a8b441e8b2c6

我不知道這個錯誤是從哪里來的?

由於您嘗試使用證書(HTTPS)從網站抓取,因此您將需要使用R包httr 在這里可以找到更多的解釋: 如何使用R(https鏈接)(使用XML包中的readHTMLTable)對受保護的頁面進行網絡爬蟲?

我在上面使用了您的代碼(略作編輯),並給出了在我的計算機上工作的最小工作示例。

全球

library(shiny)
library(magrittr)
library(rvest)

Pokemon <- read.csv('pokemon.csv', stringsAsFactors = FALSE)

用戶界面

ui <- fluidPage(
    sidebarPanel(
        selectInput(inputId = "pokemon1", 'Choose a Pokemon:', c(Pokemon$Name))),
    mainPanel(
        verbatimTextOutput("value"))
)

服務器

server <- function(input, output) {

    output$value <- renderPrint({
        pokemon <- input$pokemon1
        URLpokemon <- paste(c("https://bulbapedia.bulbagarden.net/wiki/", pokemon,"_(Pok%C3%A9mon)"), collapse="")
        # Read and parse HTML file
        pokemonSummary1 <- URLpokemon%>%
            read_html() %>% # R please help me read this HTML code
            html_nodes("p")%>% # type of HTML object
            .[[1]]%>%
            html_text()
        pokemonSummary2 <- URLpokemon%>%
            read_html() %>% # R please help me read this HTML code
            html_nodes("p")%>% # type of HTML object
            .[[2]]%>%
            html_text()
        pokemonSummary3 <- URLpokemon%>%
            read_html() %>% # R please help me read this HTML code
            html_nodes("p")%>% # type of HTML object
            .[[3]]%>%
            html_text()

        textAlmanac <- paste(c(pokemonSummary1,pokemonSummary2,pokemonSummary3), collapse=" ")

        paste(textAlmanac)
    })
}

我得到以下頁面

我希望這有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM