I am trying to use a python package inside shiny app to extract the maintext from a webpage: https://newspaper.readthedocs.io/en/latest/
what I mean by main text is the body of the article, without any adds, links, etc... (very similar to the "reader view" in safari on iphone).
To my knowledge, there is no similar package in r, if you know one please let me know.
The goal of this app is to allow the user to insert a web address, click submit and get the clean text as output.
please find the code below as well as the error message. I am using rstudio cloud.
This is the error:
Using virtual environment 'python3_env' ...
Warning in system2(python, c("-c", shQuote(command)), stdout = TRUE, stderr = TRUE) :
running command ''/cloud/project/python3_env/bin/python' -c 'import sys; import pip; sys.stdout.write(pip.__version__)' 2>&1' had status 1
Warning in if (idx != -1) version <- substring(version, 1, idx - 1) :
the condition has length > 1 and only the first element will be used
Warning: Error in : invalid version specification ‘’, ‘ ’
52: stop
51: .make_numeric_version
50: numeric_version
49: pip_version
48: reticulate::virtualenv_install
47: server [/cloud/project/python in shiny.R#42]
Error : invalid version specification ‘’, ‘ ’
and this is the code:
# Python webpage scraper followed by r summary:
library(shiny)
library(reticulate)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput("web", "Enter URL:"),
actionButton("act", "Submit")
),
mainPanel(br(),
tags$head(tags$style(HTML("pre { white-space: pre-wrap; word-break: keep-all; }"))),
verbatimTextOutput("nText"),
br()
)
)
)
server <- function(input, output){
#1) Add python env and packages:
reticulate::virtualenv_install('python3_env', packages = c('newspaper3k', 'nltk'))
py_run_string("from newspaper import Article")
py_run_string("import nltk")
py_run_string("nltk.download('punkt')")
#2) Pull the webpage url:
webad <- eventReactive(input$act, {
req(input$web)
input$web
})
observe({
py$webadd = webad
py_run_string("article = Article('webadd')")
py_run_string("article.download()")
py_run_string("article.parse()")
py_run_string("article.nlp()")
py_run_string("ztext =article.text")
py_run_string("r.ntexto = ztext")
output$nText <- renderPrint({
r.ntexto
})
})
}
shinyApp(ui = ui, server = server)
Related
I try to run a shiny app on R studio, I get the error
"ERROR: Invalid git repo specification: 'ShinySky'"
with the message at the console:
"there is no package called ‘shinysky’
Warning: Error in parse_repo_spec: Invalid git repo specification: 'ShinySky'"
Any ideas how to resolve the issue?
install.packages("shiny")
library(shiny)
ui <- fluidPage(
sliderInput(inputId ="num", label = "Choose the sample size", value=5,
min=1, max=25 ),
plotOutput("hist")
)
server <- function(input, output, session) {
output$hist <- renderPlot({
hist(rnorm(input$num))
})
}
shinyApp (ui, server)
Here is my code for a simple test app:
library(shiny)
library(shinydashboard)
library(googlesheets4)
library(googledrive)
library(DT)
drive_auth(email = "xxxx")
shinyws1<-gs4_create("WS1")
#table<-read_sheet("xxx")
# Define UI for application
ui <- fluidPage(
# Application title
titlePanel("Test App"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
numericInput("bins",
"Number of friends:",
min = 1,
max = 100,
value = 50),
actionButton("submit","Submit",class="btn-success")
),
# Show a plot of the generated distribution
mainPanel(
#blank so far
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
#results<-reactive(input$bins)
observeEvent(input$submit,{
shinyws1 %>% sheet_append(as.data.frame(input$bins))
})
}
# Run the application
shinyApp(ui = ui, server = server)
It works okay in my local server. But deployment fails.
Here is the error message generated after deployment in Shinyio server:
Error in value[[3L]](cond) : Can't get Google credentials.
Are you running googledrive in a non-interactive session? Consider:
* `drive_deauth()` to prevent the attempt to get credentials.
* Call `drive_auth()` directly with all necessary specifics.
* Read more in: https://gargle.r-lib.org/articles/non-interactive-auth.html
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted
Does anyone know how to fix it? I've tried every workaround I found online, but it didn't work.
I'm posting this because I have not managed to get the solutions posted other places working. I'm trying to re-deploy a shiny dash, but it is failing to install a package at deploy.
It's the BioConductor error, but the package it claims to fail for is a CRAN package, and so I have no idea what to do.
MRE:
library(ggseg); library(shiny); library(tidyverse); library(plotly)
# Define UI ----
ui <- fluidPage(
# Application title
titlePanel("Demonstration of ggseg package"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
radioButtons(inputId = "atlasChoice", label="Choose atlas",
choiceValues = c("dkt_3d","yeo7_3d",),
choiceNames = c("DKT", "Yeo7"),
inline = FALSE, width = NULL),
radioButtons(inputId = "positionChoice", label="Choose position",
choices = c("LCBC left","LCBC right"),
inline = FALSE, width = NULL)
),
# Show a plot of the generated distribution
mainPanel(
uiOutput("plotUI")
)
)
)
# Define server ----
server <- function(input, output) {
output$plotUI <- renderUI({
plotlyOutput("plotlyPlot")
})
output$plotlyPlot <- renderPlotly({
cc = strsplit(input$positionChoice, " ")[[1]]
ggseg3d(atlas=input$atlasChoice,
surface=cc[1],
hemisphere=cc[2]
)
})
}
# Run the application
shinyApp(ui = ui, server = server)
My repos are set as so:
getOption("repos")
BioCsoft
"https://bioconductor.org/packages/3.7/bioc"
BioCann
"https://bioconductor.org/packages/3.7/data/annotation"
BioCexp
"https://bioconductor.org/packages/3.7/data/experiment"
BioCworkflows
"https://bioconductor.org/packages/3.7/workflows"
CRAN
"https://cran.rstudio.com"
And the error is as following:
Preparing to deploy document...DONE
Uploading bundle for document: 619289...DONE
Deploying bundle: 1770029 for document: 619289 ...
Waiting for task: 573690766
building: Parsing manifest
################################ Begin Task Log ################################
################################# End Task Log #################################
Error: Unhandled Exception: Child Task 573690767 failed:
Error parsing manifest: Unable to determine package source for Bioconductor package oompaBase: Repository must be specified
Execution halted
I don't know if Athanasia's solved this in the end, but I had a similar problem today, so here's what worked for me, in case it's useful for someone else :)
My app uses biomaRt, which I think depends on Biobase. When I tried to deploy, I had the error:
Error: Unhandled Exception: Child Task 601909864 failed: Error parsing manifest: Unable to
determine package source for Bioconductor package Biobase: Repository must be specified
I changed my repos settings based on instructions I found here. This alone also didn't work for me.
Once I reinstalled Biomart using BiocInstaller::biocLite(), my app deployed successfully :)
I am new to R and I am actually developing a page where a directory (string characters like "xx/xx") is given in the server and I want to take back this directory to include it in the source of my ui app.
UI:
library(shiny)
file<-textOutput("paramfile")
source(file(file), local = TRUE, encoding = 'UTF-8')
SERVER :
filedir<-renderText({
"entries/5429_param.R"
})
output$paramfile<-renderText({
filedir()
})
I then have an error :
"Warning in file(filename, "r", encoding = encoding) : cannot open
file '< div id="paramfile" class="shiny-text-output">< /div>':
Invalid argument
Error in file(filename, "r", encoding = encoding) :
cannot open the connection"
Do you know how can I remove those tags or if there is another function that can allow me to take a string in the server and to include it into a source.
Here is a basic example of a ShinyApp:
# Example of UI with fluidPage
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput("dir", label = "Enter a directory")
),
mainPanel(
verbatimTextOutput("dirPrint"),
verbatimTextOutput("lsFiles")
)
)
)
# Server logic
server <- function(input, output) {
output$dirPrint <- renderPrint({
print(input$dir)
})
output$lsFiles <- renderPrint({
fls <- list.files(input$dir)
print(fls)
})
}
# Complete app with UI and server components
shinyApp(ui, server)
If you enter the path of a directory in the textinput, the second renderPrint function is showing all files, that are found at that path.
I would suggest you go over the Shiny-Tutorials, as there seem to be some syntax-problems in your code and I am not sure what exactly you want to achieve.
I am trying to create a simple shiny app using shineFiles that allows users to select a file for download from a directory on the web.
library(shiny)
library(shinyFiles)
ui <- fluidPage(
shinyFilesButton('files', label='File select', title='Please select a file', multiple=FALSE)
)
server <- function(input, output) {
shinyFileChoose(input, 'files',
roots = (root = c('http://mirrors.vbi.vt.edu/mirrors/ftp.ncbi.nih.gov/blast/db/')),
filetypes=c('', 'txt' , '.gz' , '.md5'))
}
shinyApp(ui = ui , server = server)
However, I am getting the below error:
Listening on http://127.0.0.1:6772
Warning: Error in fileGet: Roots must be a named vector or a function returning one
Stack trace (innermost first):
60: fileGet
59: do.call
58: observerFunc
1: runApp
ERROR: [on_request_read] connection reset by peer
I need help in defining the directory as: http://mirrors.vbi.vt.edu/mirrors/ftp.ncbi.nih.gov/blast/db/