Prompt a question similar to AskYesNo, but different value - r

I want to display a similar looking prompt question to askYesNo() but with different values to select.
I want to be able to select with a click, not through the console, a unique value. I am trying the following:
next_step = askYesNo("Choose a country", default = TRUE,
prompts = getOption("askYesNo", gettext(c("Morocco", "Tunisia", "Cancel"))),)
But it still appears as
Is there any way to change those values to the ones that I want?
Any other function that might help with this issue, a list display can be also useful, where I can select only one value.

In Windows, R only offers a few variations on the dialog you show, and none of them allow you to put arbitrary strings on the buttons.
However, you can use menu() for more flexibility. For example,
menu(gettext(c("Morocco", "Tunisie", "Cancel")),
graphics = TRUE,
title = "Choose a country")
should display something useful for you. I'm not on Windows, so I can't show you what it will look like for you. On a Mac it looks like this:

Related

Displays the current value at the bottom of the SelectionRangeSlider Jupyter Notebook

I'm creating an interactive notebook by using the library ipywidgets. I'm interested in SelectionRangeSlider widget. In documentation, we have a simple example :
import datetime
dates = [datetime.date(2015, i, 1) for i in range(1, 13)]
options = [(i.strftime('%b'), i) for i in dates]
widgets.SelectionRangeSlider(
options=options,
index=(0, 11),
description='Months (2015)',
disabled=False
)
That creates folowing slider :
I would like to change the position of the current values selected, putting it at the bottom, like that:
I've read documentation but I couldn't find a way to do this. Anyone knows if it's even possible to change this position? Thanks a lot.
Others have done things like this by setting readout=False and then making a separate widget to display the updated values. See these examples:
workaround offered by marcusreaiche for SelectionRangeSlider
TheIdealis' answer to 'Custom formatting for ipywidgets IntSlider'

How do I scrape this text from a 2004 Wayback machine site/why is the code I'm running wrong?

note: I haven't asked a question here before, and am still not sure how to make this legible, so let me know of any confusion or tips on making this more readable
I'm trying to download user information from the 2004/06 to 2004/09 Internet Archive captures of makeoutclub.com (a wacky, now-defunct social network targeted toward alternative music fans, which was created in ~2000, making it one of the oldest profile-based social networks on the Internet) using r,* specifically the rcrawler package.
So far, I've been able to use the package to get the usernames and profile links in a dataframe, using xpath to identify the elements I want, but somehow it doesn't work for either the location or interests sections of the profiles, both of which are just text instead of other elements in the html. For an idea of the site/data I'm talking about, here's the page I've been texting my xpath on: https://web.archive.org/web/20040805155243/http://www.makeoutclub.com/03/profile/html/boys/2.html
I have been testing out my xpath expressions using rcrawler's ContentScraper function, which extracts the set of elements matching the specified xpath from one specific page of the site you need to crawl. Here is my functioning expression that identifies the usernames and links on the site, with the specific page I'm using specified, and returns a vector:
testwaybacktable <- ContentScraper(Url = "https://web.archive.org/web/20040805155243/http://www.makeoutclub.com/03/profile/html/boys/2.html", XpathPatterns = c("//tr[1]/td/font/a[1]/#href", "//tr[1]/td/font/a[1]"), ManyPerPattern = TRUE)
And here is the bad one, where I'm testing the "location," which ends up returning an empty vector
testwaybacklocations <- ContentScraper(Url = "https://web.archive.org/web/20040805155243/http://www.makeoutclub.com/03/profile/html/boys/2.html", XpathPatterns = "//td/table/tbody/tr[1]/td/font/text()[2]", ManyPerPattern = TRUE)
And the other bad one, this one looking for the text under "interests":
testwaybackint <- ContentScraper(Url = "https://web.archive.org/web/20040805155243/http://www.makeoutclub.com/03/profile/html/boys/2.html", XpathPatterns = "//td/table/tbody/tr[2]/td/font/text()", ManyPerPattern = TRUE)
The xpath expressions I'm using here seem to select the right elements when I try searching them in the Chrome Inspect thing, but the program doesn't seem to read them. I also have tried selecting only one element for each field, and it still produced an empty vector. I know that this tool can read text in this webpage–I tested another random piece of text–but somehow I'm getting nothing when I run this test.
Is there something wrong with my xpath expression? Should I be using different tools to do this?
Thanks for your patience!
*This is for a digital humanities project will hopefully use some nlp to analyze especially language around gender and sexuality, in dialogue with some nlp analysis of the lyrics of the most popular bands on the site.
A late answer, but maybe it will help nontheless. Also I am not sure about the whole TOS question, but I think that's yours to figure out. Long story short ... I will just try to to adress the technical aspects of your problem ;)
I am not familiar with the rcrawler-package. Usually I use rvest for webscraping and I think it is a good choice. To achive the desired output you would have to use something like
# parameters
url <- your_url
xpath_pattern <- your_pattern
# get the data
wp <- xml2::read_html(url)
# extract whatever you need
res <- rvest::html_nodes(wp,xpath=xpath_pattern)
I think it is not possible to use a vector with multiple elements as pattern argument, but you can run html_nodes for each pattern you want to extract seperately.
I think the first two urls/patterns should work this way. The pattern in your last url seems to be wrong somehow. If you want to extract the text inside the tables, it should probably be something like "//tr[2]/td/font/text()[2]"

eval parse string with hyphen returning error object 'top:' not found

Seems like a lot of the similar questions asked on here do not have accepted answers and I haven't found anything that worked for me.
I'm creating a shiny app which has download buttons. on one page the download button needs to be moved down the page under all the plots.
this works for me but is hard coded:
output$saveGraphRob <- renderUI({
downloadButton("saveGraphRob1","Download", style = "margin-top:3500px")
})
what I want to do is allow for the style to be placed under all the graphs no matter how many there are. so if my plot_count() is 6 for example, instead of 3500px it should be plot_count()*350.
trying this is returning the error: object 'top:' not found
output$saveGraphRob <- renderUI({
downloadButton("saveGraphRob1","Download", style = eval(parse(text=(paste0("margin-top:",plot_count()*350))))))
})
it's trying to evaluate the hyphen in margin-top as a minus sign, but I'm not sure what the workaround is.
Also open to other solutions to change the position of my download button.
The style= parameter is just a character string. You should not be using eval(parse()) there (or almost ever with most R code). Just use style=paste0("margin-top:", plot_count()*350, "px")

Data Table column filters not displaying properly in Shiny (Using DT package)

I have a data table I am rendering in shiny using the DT package. Each individual column has a filter at the top. All column filters are working but the formatting is somewhat strange.
Screenshot of column filters
As you can see some of the filters have the word "All" inside them and these function correctly, when you type in them the word you are typing shows up.
However some of the others do not and when I type in these the filtering mechanism does work (as in the correct rows are filtered out) but you cannot see what filter you typed in. It seems as though the cursor is way to the left in the box and not visible.
The code I use to render the data table is below:
DT::renderDataTable(X,
options = list(pageLength = 10,
searching = TRUE,
autoWidth = TRUE,
columnDefs = list(list(className = 'dt-center', targets = "_all"))
),
filter = "top"
)
(Still) Trying to solve a different issue, I set padding to zero in CSS for .has-feedback .form-control and at least I can now see "All" in every filter cell. More specifically:
.has-feedback .form-control {
padding-right: 0px;
}
Hope it helps.
P.S. It's easy to play around with this stuff using the right-click & 'inspect' functionality of Chrome (and I guess Firefox).
To my knowledge this is a known bug for DT::renderDataTable as long as you use server-side processing (which is the default setting for DT::renderDataTable) for bigger tables (i.e. many columns). If you set server = FALSE, the filters should be shown properly...

R Shiny SIZE / WIDTH OF FILTERS WHEN USING RENDER DATA TABLE

I'm using renderDataTable with the filter-option.
Sometimes the values in the filter-selection-window cannot be correctly read (unless after choosing one), because the column has a smaller width.
If possible, I would like to keep the autoWidth option, and ask if there is a way to read what is inside the filter, or if it is possible to enlarge the area of the filter-selection-window.
renderDataTable(data,filter = 'top',options = list(autoWidth = TRUE))
enter image description here
You need to give more information and reproducible code of what you trying to do. What is your server.r and ui.r steps ? options = list(autoWidth = TRUE)), generally applies to datatable columns. Filter options are passed to ui.r. By, default it is autowidth. The Rshiny examples have detailed information about them in below link and hope it helps you to reach your goal.
http://shiny.rstudio.com/gallery/basic-datatable.html

Resources