Skip to content

DashR does not currently have the get_asset_url method for loading asset URLs like Dash for Python #158

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

Closed
HammadTheOne opened this issue Dec 23, 2019 · 3 comments
Assignees

Comments

@HammadTheOne
Copy link
Contributor

HammadTheOne commented Dec 23, 2019

As originally referenced in a DashR docs issue, Dash for R currently lacks this method which is featured in the Python version. Based on the Python implementation, it would grab the asset URL from the assets directory without needing to specify the exact path.

@rpkyle @HammadTheOne - Do you think we could get a get_asset_url into Dash for R before the next release? Here is the implementation in Python:
https://github.com/plotly/dash/blob/e622f2a31202302d0c305c56e738d1ea369403e6/dash/dash.py#L1559-L1566

If it's not in Dash for R, then we can include it in this example as a helper function.

Originally posted by @chriddyp in https://github.com/plotly/dash-enterprise-docs/pull/95

@rpkyle
Copy link
Contributor

rpkyle commented Dec 23, 2019

Thanks @HammadTheOne -- I meant to reply earlier; just did that now.

It's correct to say that Dash for R doesn't have this method, because the function isn't associated with the Dash R6 class, but rather an unexported function in utils.R:

dashR/R/utils.R

Lines 583 to 598 in 5f2942c

get_asset_url <- function(asset_path, prefix = "/") {
# the subpath is stored in the names attribute
# of the return object from get_asset_path, so
# we can retrieve it using names()
asset <- names(asset_path)
# strip one or more trailing slashes, since we'll
# introduce one when we concatenate the prefix and
# asset path
prefix <- gsub(pattern = "/+$",
replacement = "",
x = prefix)
# prepend the asset name with the route prefix
return(paste(prefix, asset, sep="/"))
}

@HammadTheOne I can make this change via PR, and will ask you for review.

@rpkyle
Copy link
Contributor

rpkyle commented Dec 23, 2019

Thanks @HammadTheOne -- I've responded in the original thread, but I think I'll have to add in a check for the names attribute to make this usable by developers, even if exported. If there is no name associated with the path, the function will infer it from the asset map, otherwise it will use the one passed.

@rpkyle
Copy link
Contributor

rpkyle commented Jan 3, 2020

Closed by way of #160.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants