-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to compute and cache a screenshot using rest api in superset #15118
Comments
Hi, @pritypriya25 , the PK is chart id(aka slice id), you can get this
|
thank you @zhaoyongjie . Now I know what is the slice id. But still I can't get my output from hitting the api chart/{pk}/cache_screenshot. |
@pritypriya25 ,I want know , how to use access_token? can Screenshot? |
@YangJianFei you can generate the token through POST api/v1/security/login. You can find out the request body on the official superset website https://superset.apache.org/docs/rest-api |
Hi, have you get a solution? i face same issue... |
Solving this requires multiple steps. First, you have to adjust several values in your superset_config.py: FEATURE_FLAGS = {
"THUMBNAILS": True,
"THUMBNAILS_SQLA_LISTENERS": True,
} provide valid cache configs for CACHE_CONFIG = {
'CACHE_TYPE': 'FileSystemCache',
'CACHE_DEFAULT_TIMEOUT': 60 * 60 * 24,
'CACHE_THRESHOLD': CACHE_THRESHOLD, # integer, limit of items in the cache
'CACHE_DIR': BASE_CACHE_DIR, # the directory where the cache should be stored
} additionally, configure the from cachelib.file import FileSystemCache
import os
RESULTS_BACKEND = FileSystemCache(
cache_dir=os.path.join(BASE_CACHE_DIR, 'results/'),
threshold=CACHE_THRESHOLD,
default_timeout=CACHE_DEFAULT_TIMEOUT
) Next, you need to provide a celery config (the one below is copied from the official superset documentation without any modifications): class CeleryConfig(object):
BROKER_URL = 'redis://localhost:6379/0'
CELERY_IMPORTS = (
'superset.sql_lab',
'superset.tasks',
'superset.tasks.thumbnails'
)
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
CELERYD_LOG_LEVEL = 'DEBUG'
CELERYD_PREFETCH_MULTIPLIER = 10
CELERY_ACKS_LATE = True
CELERY_ANNOTATIONS = {
'sql_lab.get_sql_results': {
'rate_limit': '100/s',
},
'email_reports.send': {
'rate_limit': '1/s',
'time_limit': 120,
'soft_time_limit': 150,
'ignore_result': True,
},
}
CELERY_CONFIG = CeleryConfig last steps in the WEBDRIVER_TYPE = "firefox"
WEBDRIVER_BASEURL = "http://localhost:8088" # or whatever URL your superset instance is running on, the webdriver will use this URL to connect to superset in order to take a screenshot
THUMBNAIL_SELENIUM_USER = "admin" # any user with permissions to view all charts is sufficient now, in your superset environment, make sure you have a redis server running and listening on port 6379 (otherwise, adjust the redis port in the settings above). Also, you will need firefox and geckodriver. Make sure that your redis server can write data to the disk by connecting to it via CONFIG SET dir /app/superset_home/redis # where the database will be stored, the directory must exist
CONFIG SET dbfilename redis.rdb # or any other filename Start celery using Now, you should be able to take screenshots and see thumbnails of your dashboards Note: I am not sure whether all settings are actually needed, this is just the setup that worked for me. |
@Hvitgar .. Thanks for providing the solution. Actually I am cloning the git repo and running the superset. Could you please provide the file path even because I can't find the file in the repository ? |
Thank you @Hvitgar for your solution, i have implement it, but when i access screenshot url return 404 not found. Below is log from superset worker: `
|
hey @isandyawan, I assume that your error is related to this line in the superset_config.py: WEBDRIVER_BASEURL = "http://localhost:8088" # or whatever URL your superset instance is running on, the webdriver will use this URL to connect to superset in order to take a screenshot For taking the screenshot, a browser session accesses the URL above, renders the chart and than produces a screenshot so you have to make sure that superset is accessible on the URL above (it might be a DNS name or IP if hosted publicly, or localhost if on your machine). Also, make sure that the port is correct. Superset offers a health check under If you are still not able to solve it, please give me more information about the way you are running superset. Are you using docker? Local installation? Cloud? |
Hi @Hvitgar , thanks for your answer, i was try to change WEBDRIVER_BASEURL with IP but it cannot work too. I also check using 'curl localhost:8088/health ' and it return 'OK'. I using docker to running superset |
did you do the curl inside your container?If not, please try again from the container as the port inside the container might be different to the one you are using on the system running the container |
@Hvitgar.. Thanks for the solution. It's working for me. Now I am getting the screenshot and image URL. |
This issue is not working well anymore, at least on my configuration, I made it work using the conf file from #20756 |
I'm able to cache the screenshot but not able to get the image using the image_url that I got with cache response. How do I use image_url to get the image of chart? Made superset_config.py file using this here |
@vinodtrekea |
I have initiated the discussion on this here |
I want to get the chart by hitting the API. I read the documentation and found that I can do this by /chart/{pk}/cache_screenshot/
But I am unable to know what is the value of pk over here. It is an integer value and provides a path but I am unable to get the value. Can someone guide me on how can I get the value?
The text was updated successfully, but these errors were encountered: