At work we use Shiny to develop management dashboards. The information source used to be flat files previously extracted from the database but now we are trying to develop a "live" dashboard allowing the user to query the database from within the dashboard. The dashboard is reached using a url and there is no login required to view the dashboard. Just point the browser and the dashboard loads.
I've got it working fine except for one problem. If two users are using the dashboard at the same time, running the same queries and creating the same tables, the results can become mixed. One user will see the results of another.
Queries are ran using an actionButton that runs a function such as:
dataTbl <- function(<select criteria>) {
sqlQuery(connection, "select * from ... ")
}
How can each user have their own unique session so that regardless of the number of users at any one time, each is separate and independent of the others?
You can do string search and replace, I would also suggest that you use promises package to do the querying https://rstudio.github.io/promises/articles/shiny.html
dataTbl <- function(table,products) {
qr <- "select * from TABLE where product = PRODUCTS"
qr <- gsub("TABLE",table,qr)
qr <- gsub("PRODUCTS",products,qr)
sqlQuery(connection,qr)
}
Related
LookerML question:
I have got this snowflake query which joins one static table (does not refresh) and one table that refreshes every day.
I want to pop this query into Looker and create a simple Looker dashboard using it.
Two options I think are available to me to do so:
Create view file and PDT but that would mean I need to add a trigger value and the data including the static table would refresh, right? - Isn't this very inefficient?
Create regular DT with the explore being a PDT?
A derived table will be temporary and will not be written to the database. Each time the dashboard is refreshed, a query will be rerun against your data source to extract data.
A persistent derived table will store the data results in a database, whilst using a persistent strategy to refreshing the data based on time or a data driven trigger. If the persistent data already exists and is still valid, Looker will extract the results from the persisted data rather than creating a query against your source database.
I have models in SQL that update the data everyday automatically. Info about the models is stored in a table. One of the columns I called "error". It is a column with zeros, which change to 1 if the performance of the model is below a certain threshold. Now my question is whether it is possible that I get notified if an entry of the "error" column becomes 1.
The models I discussed are R scripts that I run in SQL. The scripts predict whether a customer makes a purchase or not.
I'm using Microsoft SQL Server.
To get a more immediate notification than an email, you can also use a tool like Notify17, which would send you a push notification on your browser/mobile phone (it is very easy to miss out emails).
There is a basic R recipe for it, which boils down to:
notify17 <- function(rawAPIKey, title, content = '') {
hookURL = paste0("https://hook.notify17.net/api/raw/", rawAPIKey)
query <- list(title = title,
content = content)
resp <- httr::POST(hookURL, body = query, encode = "form")
print(httr::content(resp))
}
# Usage:
notify17('RAW_API_KEY',
"Model training finished")
All you need is to get a raw API key from the dashboard and use it in a script.
I used the R script to send an email.
this will explain how to do it:
how do you send email from R
I'm learning angularjs, firebase, angularfire by building a sample app. It's a dictionary app that any one can add a word, add several explanation to the word, add several common usage to the word, add example centences to the word. People can freely add new word via this web app. OR people can freely realtime search a word and display the content of that word. When I build the app.
I found everytime when I search a word, I have to load all the data and then check if the query string exist in the data and then display the content if exist. So, it's quite heavy if the library become very big.
How can I query a string if it exist from the server side and if exist, just download that piece of data?
Here is a very simple example that is on the firebase site (Retreiving data). I suggest you take a look at that page, there is a lot more info there about this subject. Now the example:
var ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs");
ref.orderByChild([the child node to compare to]).equalTo([what you are searching]).on("child_added", function(snapshot) {
//do something with the data in snapshot
});
Ref : http://shiny.rstudio.com/gallery/datatables-options.html
I want to get access to the search boxes - the global and the column ones to use them in a custom sql query I run on the backend. (I have very limited js knowledge)
For a datatable named myDT, the global search bar can be accessed with input$myDT_search in a observe block.
In an ASP.NET WebForms application I would like to allow the end-user to browse selected raw data in an sql-server database.
However, I would like to restrict access for the user to only view some of the data based on the username.
I'm not sure how to do this in a way that is possible for the user to understand, since SQL is not necessarily known to the user.
What options do I have here?
As a basis for this I have considered creating one sql function per table in question. That function should return the data that the user is allowed to view, e.g.,
CREATE FUNCTION ufn_RawData_Employee(#username nvarchar(256))
RETURNS TABLE
AS ( SELECT * FROM Employee
WHERE [#username is allowed to view the given Employee] )
In a webpage the end-user might then type an SQL-like statement like
SELECT Name, HireDate FROM ((Employee))
where (([TableName])) then could be replaced by ufn_RawData_[TableName]([UserName]) before calling the database.
(For security reasons such calls could then be performed by a sql user whose only permissions are SELECT permissions to these functions.)
However, this approach might be too difficult for the end-user. I would like to know if an easier/user-friendlier solution exists for the end-user to browse selected raw data?
If you are only showing the user data from one table, or one view (which would probably be more useful) then yes you could store the name of that view in a table and retrieve it with a function. You could then display the data in pages, and make sure your standard select scripts have a built in search function if necessary.
There is no need for the user to write SQL if they are only getting data from one table or view. If you need to provide multiple potential tables/ views, then let them choose from a drop down, but it doesn't sound worthwhile to allow them to write their own SQL queries.