DataTable - get row_ids of displayed data on page - plotly-dash

I use pagination (10 rows per page). I would like to get via a callback the row ids of rows which are displayed on the current page.
I found the 'derived_viewport_row_ids' attributes promising, but it results in a list of Nones.
#app.callback(Output('main-table','style_data_conditional'), Input('main-table','derived_viewport_row_ids'), prevent_initial_call=True)
def gradient_style(page_row_ids):
print(page_row_ids)
return no_update
Does anybody have an idea how to access this information?

Related

Trying to crawl some data on Google Sheets but getting beat by XPath

I'm trying to make a sheet for study purposes on stock market, and I'm using this website to get the data from. Taking this stock as example.
My goals here are:
I want to grab some of the indicators from this div area (such as P/L, LPA, M. LÍQUIDA, and others);
And some of the numbers from this tables's first column (such as row 11, 15, and others).
My issues:
I'm not being able to fetch the data that I want from the div with the IMPORTXML function, neither with copying the XPath nor trying to find a specific class name to find a match.
I'm being able to fetch the specific number that I want, but it's returning 3 different values from 3 different rows (I want only the first one), due the XPath that I'm using //table/tbody/tr[11]/td[2]/span.
There's 2 more tables down the page that uses the same XPath, and the function is returning the values from row #11 of the other tables, as you can see here. The only thing that makes the 3 different from one another it's their divs, but I'm not being able to figure out how to manipulate these divs. There's any way to fix this or any function that automatically deletes the other 2 rows?
Can someone give me a light? :(
It's almost always easier to find the values you need by a reference. This should work to get the 20,76 from the first table
(//*[contains(text(), 'P/L')]/following::strong)[1]
As far as the second table goes, this should get 52.562,18 M
(//span[contains(text(), 'Receita Líquida')]/following::td)[1]
If you need to get different columns, you can just pass a higher index, this will return -0,07% for instance.
(//span[contains(text(), 'Receita Líquida')]/following::td)[5]
I also highly recommend getting some sort of xpath tester addon for your browser to play around with these if you don't already have one. I use ChroPath:
Firefox -
https://addons.mozilla.org/en-US/firefox/addon/chropath-for-firefox/
Chrome - https://chrome.google.com/webstore/detail/chropath/ljngjbnaijcbncmcnjfhigebomdlkcjo?hl=en-US

Unable to retrieve item count for Sharepoint List through Microsoft Graph API

I am currently using the Microsoft Graph API to return data in JSON for a specific list through this URL:
https://graph.microsoft.com/v1.0/sites/{siteID}/lists/{listID}/items/{itemID}
I would like to return data for all the items in the list by iterating through the itemID which is a number like 1,2,3. Although I can do that, I don't know what number to iterate to - does anyone know the API call or the URL for getting the item count in a list. If I send a GET Request to the following URL:
https://graph.microsoft.com/v1.0/sites/{siteID}/lists/{listID}/items
I only get back 235 list item JSON objects (much less than the 1200 that actually exist in the list) so I can't read off the last json object ID as the count.
I can do a while loop till I get an 'id doesn't exist error' but there are some items that are being regularly deleted hence I may encounter the same error there as well.
It can retrieve only few items when sending the API query (100-200) items. So try to use the $top query parameter
Using top query parameter. You are able to retrieve maximum 3000 items using Graph API
https://graph.microsoft.com/v1.0/sites/{siteID}/lists/{listID}/items?$top=3000
Upvote if accepted as a answer

Google Bigquery json API, pageToken has no effect

I'm trying to implement the JSON api (v2) of bigquery. In my code I get the same behaviour as on the documentation page for tabledata-list
My table size is about 11.000 rows. In the documentation page I fill in the following parameters:
ProjectId = X
DatasetId = Y
TableId = Z
MaxResults = 10000 #I want to paginate my results
This returns 10.000 rows and a pageToken. So I do the same request and now I set the page token so that I get the next page of results.
And that returns the same 10.000 rows as before. I expected this to do pagination as described on this page:
All collection.list methods return paginated results under certain circumstances. The number of results per page is controlled by the maxResults property
A page is a subset of the total number of rows. If your results are more than one page of data, the result data will have a nextPageToken property. To retrieve the next page of results, make another list call and include the token value as a URL parameter named pageToken.
Where do I go wrong?
EDIT:
My colleague pointed out to me that on the other documentation pages the result contains a nextPageToken except the response contains a pageToken. The difference being that where pageToken refers to the current page, the nextPageToken refers to the next page.
However the documentation states it should return a nextPageToken (except when there is no more data). But len(table) > len(result)
On the same page it's mentioned that there is a difference for TableData.List() call
The bigquery.tabledata.list method, which is used to page through
table data, uses a row offset value or a page token.
So for TableData.List() you must use the row offset value to paginate, and in order to access previous pages you can use your hashes from your session. This is built because with large volume and big data, you cannot pre-cache the next set of data from your worker pool.
You can help improving the documentation, by using the link on top right of each page that says: Feedback on this document feel free to use that to reach out with improvements.
Also you can submit issues to https://code.google.com/p/google-bigquery/issues/list
Unfortunately, the field returned for TableData.List() that contains the logical "next page token" is literally named "pageToken", rather than "nextPageToken".
Other APIs, like Datasets.List(), return a field literally named "nextPageToken" which contains the logical "next page token".
It's a case of inconsistent naming, but hopefully this helps clear up some confusion.

Pagination and form tag issue

i have two .php files: trialform.php and trialaction.php
User chooses search terms using <select> tags on trialform.php, and then that information goes to trialaction.php that has mySQL $query=SELECT * ... which contains variables like $expression1 etc. (Depending on the user's choice).
It works fine. But I wanted to implement pagination from this source
Now my query works only for the first pagination page, when I click on the second and third...it does not show any results. The problem is that the $query=SELECT * ... refers to trialform.php, and it does not exist after the user pressed "Submit".
Do I have to split my $_POST code section in a separate .php file in order to be able to use pagination and <form>?
this is often performed with parameters on subsequent pages passing updates to the page number (gets you the start parameter) and limit as can be seen here http://dev.sencha.com/deploy/ext-4.0.0/examples/grid/paging.html
and viewing the http headers in fiddler. for page 4 you get
GET /forum/topics-browse-remote.php?_dc=1368498808032&page=4&start=150&limit=50
and page 5 is
GET /forum/topics-browse-remote.php?_dc=1368498808032&page=5&start=200&limit=50
so subsequent pages (prior or next) know where to start. naturally the parameters are fed into the select statement such as
select * from employee limit 200,50 # start,limit

sfPropelPager reduce queries

i'm working in a symfony project and using sfPropelPager to show a paged list of elements.
The problem is that with a great amount of data to list (i.e. thousands of registers) it makes a query to the database for each page to show!!!! That means about 100 extra queries in my case, and that is unacceptable.
Showing some of my code: the function that returns the pager object
$pager = new sfPropelPager('MyTable',sfConfig::get('sfPropelPagerLines'));
$c = new Criteria();
$c->add('my_table_field',$value);
$c->addDescendingOrderByColumn('date');
$pager->setCriteria($c);
$pager->init();
return $pager;
So, please, if you know a way to get all the results with only one query, it would be a great solution for my problem. Otherwise i must implement that list with an ajax call for every page the user wants to see
Thank you very much for your time.
I'm not sure to get your problem but, anyway, avoid the use of Criteria. Try to make queries with the ModelCriteria API: http://www.propelorm.org/reference/model-criteria.html.
For each paginated page, a query to the database will be done, this is the standard behavior for all pagers I know. If it's related to related objects (assuming you want to display information from relations), you may want to create a query that links those objects before to paginate, that way you'll get one query per page for all your data to display.
Read this doc for instance: http://www.propelorm.org/documentation/03-basic-crud.html#query_termination_methods
At last i did'nt get a solution for the problem, i had to implement the list via AJAX call, calling to a function that returns the requested page, so at the load of the page, no query for this list is slowing the user experience.
Thank you anyway to help me :)