I just started using Ipyvuetify today and I wanted to build a simple multi-select function. Please find my code below:
import ipyvuetify as v
hospital_select=v.Select(
prepend_icon='mdi-hospital-box',
style_='width: 400px',
v_model='e6',
items=[
'Lion Heart Hospital',
'Kindoya Hospital',
'Port Loko Government Hospital',
'Holy Spirit Catholic Hosp'
],
label='Hospital Name',
multiple=True,
chips=True
)
It should be pretty straight forward, but I can't select any options from the drop-down menu.
multi-select drop-down menu
PS: single-select works
the value 'e6' is not part of the list provided in the item trait which I think leads to a bug. In #ac24 answer, the v_model will be unset and it will not be possible to retreive the list
try this instead :
import ipyvuetify as v
hospital_select=v.Select(
prepend_icon='mdi-hospital-box',
style_='width: 400px',
v_model=None,
items=[
'Lion Heart Hospital',
'Kindoya Hospital',
'Port Loko Government Hospital',
'Holy Spirit Catholic Hosp'
],
label='Hospital Name',
multiple=True,
chips=True
)
and use hospital_select.v_model to retrieve the widget value as a list
This works for me if you remove the v_model='e6' kwarg, no idea why though.
hospital_select=v.Select(
prepend_icon='mdi-hospital-box',
style_='width: 400px',
items=['Lion Heart Hospital','Kindoya Hospital','Port Loko Government Hospital','Holy Spirit Catholic Hosp'],
label='Hospital Name',
multiple=True,
chips=True
)
Related
I'm playing with Streamlit, and there is some behaviour I don't know how to manage.
I'd like three widgets in a collapsible section, but when I collapse/expand the section the values go back to their defaults, making correcting the values a bit of a pain for the user.
Here is some sample code:
import streamlit as st
with st.beta_expander("Describe your baby"):
age, weight, sex = st.beta_columns((1,1,1))
with age:
baby_age = st.number_input('Baby age in months', min_value=0.0, max_value=36.0, step=0.25, value=2.0)
with weight:
baby_weight = st.number_input('Baby weight in KG', min_value=0.0, max_value=16.0, step=0.01, value=6.0)
with sex:
baby_sex = st.selectbox('Baby sex', ['Male', 'Female'])
st.write(f'Your {baby_age} month old {"boy" if baby_sex=="Male" else "girl"} is {baby_weight}kg.')
What is the intended way to handle this?
It seems to now work for streamlit>=1.8.0:
Of course, it also works with the st.expander too. You don't need the beta_ in the new versions.
I'm trying to get the City, Country and Region back from the site using Beautiful Soup on this site:
https://www.geodatatool.com/en/?ip=82.47.160.231
(Don't worry that's not my IP; dummy ip)
This is what I'm trying:
url = "https://www.geodatatool.com/en/?ip="+ip
# Getting site's data in plain text..
sourceCode = requests.get(url)
plainText = sourceCode.text
soup = BeautifulSoup(plainText)
tags = soup('span')
# Parsing data.
data_item = soup.body.findAll('div','data-item')
#bold_item = data_item.findAll('span')
for tag in tags:
print(tag.contents)
I just get an array back of all span content. Trying to narrow it down to specifically my needs but that's not happening anytime soon.
Can someone help me out with this?
This should work. Basically we find all divs with class: 'data-item', and then in here we are looking for the 2 spans, where the first span is the city:, country:, etc. and the second span contains the data.
data_items = soup.findAll('div', {'class': 'data-item'})
# Country
country = data_items[2].findAll('span')[1].text.strip()
# City
city = data_items[5].findAll('span')[1].text.strip()
# Region
country = data_items[4].findAll('span')[1].text.strip()
In general this works, but if the website shows different data or orders the data differently per search, we might want to make the code a bit more robust. We can do this by using regex to find the country, city and region fields. The solution to that would look as follows:
# Country
country = soup.find(text=re.compile('country', re.IGNORECASE)).parent.parent.findAll('span')[1].text.strip()
# City
city = soup.find(text=re.compile('city', re.IGNORECASE)).parent.parent.findAll('span')[1].text.strip()
# Region
region = soup.find(text=re.compile('region', re.IGNORECASE)).parent.parent.findAll('span')[1].text.strip()
We try to find the pattern 'country', 'city' or 'region' inside the HTML code. Then grabing their parent 2 times to get the same results as the data_items as in the codeblock before and perform the same operations to get to the answer.
It's easier to do it with css selectors:
data_items = soup.select('div.sidebar-data div.data-item')
targets = ['Country:','City:','Region:']
for item in data_items:
if item.select('span.bold')[0].text in targets:
print(item.select('span.bold')[0].text, item.select('span')[1].text.strip())
Output:
Country: United Kingdom
Region: England
City: Plymouth
I'm a wordpress beginner.
I have some custom fields that contain multiple values, and I want to output them.
One custom field has multiple values (press review quotes for a show - reviewchart-review). But I also want it to output the corresponding value in the reviewchart-publication field (the name of the publication the press quote is from).
This is the code:
$post_meta_array = get_post_meta($post->ID, 'reviewchart-review');
$review_pub = get_post_meta($post->ID, 'reviewchart-publication');
foreach ($post_meta_array as $post_meta) {
echo $review_pub . '<blockquote><p>' . $post_meta . '</p></blockquote>';
}
This is the output:
Array
"Fresh and assured. This Restoration comedy has japes aplenty. Winning performances from Susannah Fielding and Geoffrey Streatfeild."
Array
“Simon Godwin’s production of George Farquhar’s play is one of the most consistently funny productions of a Restoration comedy you’re likely to see.”
Any help appreciated,
Thanks
Typing keyword in search box, say 日光 (Chinese words), I can see the live search result hinting the target items. It works well for types of Products.ATContentTypes (NewsItem, Page), but fails to find the same keyword for items of my custom type. Here is the partial code for the type:
atapi.TextField(
'history',
storage=atapi.AnnotationStorage(),
default_output_type='text/x-html-safe',
widget=atapi.RichWidget(
label=_(u"Establishment History"),
description=_(u"Enter Establishment History."),
rows = 20,
),
),
I do try add searchable=1, to the field, and re-catalog, but still no working. What am I missing?
Add the keyword searchable=True to your definition.
atapi.TextField(
'history',
searchable=True,
storage=atapi.AnnotationStorage(),
default_output_type='text/x-html-safe',
widget=atapi.RichWidget(
label=_(u"Establishment History"),
description=_(u"Enter Establishment History."),
rows = 20,
),
),
I am using embed.ly API, but when using example code i just get a long string of data and not an object i can access the different parts of, here is my code:
embedly_api = Embedly::API.new :key => 'HIDDEN', :user_agent => 'Mozilla/5.0 (compatible; mytestapp/1.0; my#email.com)'
url = 'http://www.guardian.co.uk/media/2011/jan/21/andy-coulson-phone-hacking-statement'
obj = embedly_api.oembed :url => url
obj[0].marshal_dump
The obj[0] returns:
{:provider_url=>"http://www.guardian.co.uk/", :description=>"11.25am: Andy Coulson, the the director of communications at No 10, is to make a \"personal statement\". He has been under pressure in recent months over the phone-hacking scandal, with a slew of revelations in a number of civil court cases that appeared to bring the scandal closer to his door.", :title=>"Andy Coulson resigns – as it happened", :url=>"http://www.guardian.co.uk/media/2011/jan/21/andy-coulson-phone-hacking-statement", :thumbnail_width=>140, :thumbnail_url=>"https://static-secure.guim.co.uk/sys-images/Guardian/Pix/pictures/2011/1/14/1295010840306/Andy-Coulson-003.jpg", :version=>"1.0", :provider_name=>"Guardian", :type=>"link", :thumbnail_height=>84}
What i want is to access obj[0].provider_url, description and so on... how?
obj[0][:provider_url]
should do the trick.