We are building a Shiny app and plan to share the link to shinyapps.io.
We are wondering if there is any way to collect feedback from users - e.g. is there a way to have a text input field and permanently save the inputs for us?
Many thanks!
There is this project: ShinyChat which can be used as starting point for user feedback collection system.
Link to app: Live Chat
So in theory you need to have global reactiveValues() where you store your log.Rds and then you add user input to that log file. You may want to use R package stringgr. Example code:
library(stringgr)
log <- reactiveValues() #This have to be outside shinyServer so that all users can see it
shinyServer(function(input, output, session) {
addFeedBack <- function(file, string) {
...
return(modifiedFile)
}
observe({
log$logfile <- addFeedBack(log$logfile, input$userFeedback)
})
}
EDIT:
I did some research and actually there is really nice article and example in an official shiny page: Share data So you will encounter some problems if you are planning to host your app on ShinyApps.io. and article gives solution for that.
Related
so I thought I had figured this out thanks to previous help (Updating R shiny data), but I have come across more issues. I didn't notice these issues since I got busy doing other things in my job. But turns out it is not auto-updating the app on shinyapps.io. I'll post the test code I have made in the server section:
dftest<-reactiveFileReader(1000,session,"Crop Registration 2022.xlsx",readFunc = read_excel,sheet = "CSV")
output$table2<-renderTable(
{
dftest2<-filter(dftest(),Variety=="Test1", Week>25 )
dftest2
}
)
What I found is after publishing the app on shinyapps.io any changes made to the excel sheet "CSV" do not show up. What I want is I can add data to the original excel sheet the app on shiny apps auto updates with the new data. Am I approaching this problem completely wrong? Or is it even possible via shinyapps.io ?
Is it possible to clear the Shiny cache history when reloading an app? Specifically, I have a textInput for adding a title that doesn't clear when the app is restarted. In other words, all of the titles entered into the app on previous runs have been "remembered" and show up in a dropdown list when the app is rerun or restarted again. I have tried using shinyjs::reset, but that clears the current value and not the ones in the "history". I've also tried updateTextInput with an action button set to " ", but also clears only the current value and not the ones in the "history". I have also tried setting ui as a function using:
ui <- function(req) {
fluidPage(...)
}
as well as:
I found that cache of R Shiny server is updated when the date of creation for the file "app.R" is changed.
So, here is the trick I used:
server <- function(input, output, session) {
Trick file date creation update
onStop(function() {
# File name
p <- paste0(getwd(), "/app.R")
# Update file 'date creation'
Sys.setFileTime(p, now())
}) # onStop
} # server
The idea is to update the date of "app.R" creation after each session.
Neither of these solutions worked for me. Finally, I found this post:
I also found this post:
I have been struggling with this problem for quite a while, and thought I had tried everything, including putting a js button on the shiny sidebar to manually refresh (unfortunately that did not work either). There are two things that did work for me:
Make sure all code to read data from files is NOT in a code chunk with a name OTHER THAN global OR
Manually restart the shiny server when new data is uploaded
Obviously the first one is much more manageable, and a solution that I wish I had known weeks ago when I started playing with workarounds.
But I am not sure what is involved in implementing either, so if someone could clarify that, that would be great.
Any help would be much appreciated.
IS there a way to highlight shiny app coding when the code is changed?
For example, the "Hello Shiny" example app:
library(shiny)
runExample("01_hello")
creates an app that includes the app code. This code is highlighted every time an action is executed (highlighting the code that is impacted).
How do I do this with my own app??
Maybe this can help:
shiny::runApp(display.mode="showcase")
You can get more information about this here. See Showcase Mode
If you're using shinyApp() directly, try this:
shinyApp(ui, server, options = list(display.mode='showcase'))
Let's take a look at one of the demos.
runExample("09_upload")
I am using the supplied file to perform some computations and to display an aggregated performance across all uploaded files. Therefore, I use something like
tryCatch(compute.smth(), error=function(e){})
so that the displayed result is not affected by the bad input. However, I'd like to indicate somehow that uploading the bad file lead to an error, notifying the user about the problem with his input. It'll be something like
tryCatch(compute.smth(), error=badFile())
where badFile() should modify some displayable output. Any ideas?
As a last resort, this is probably an option, but I'd like some native Shiny.
You can show alerts like below with the ShinySky package: https://github.com/AnalytixWare/ShinySky
You can install the package using
install.packages("devtools")#if not alrady installed
devtools::install_github("ShinySky","AnalytixWare")
Place a shinyalert(id) in the ui.R for where you want the alert to appear.
In your server.R
Make sure you have a 3 parameters funciton being passed to shinyServer e.g.shinyServer(function(input, output,session) {
use showshinyalert(id,HTMLText,session) to show the alert. Clicking on the alert will dismiss it.
See this gist for example https://gist.github.com/xiaodaigh/7707701
Run this too see an example
shinysky::run.shinysky.example()
I set up a shiny app that checks for a GET string and presents a link if a file matching the id argument exists. Now what I would like to do is have the page redirect straight to the download file if a valid query is detected in the URL. Does anybody know of the syntax to insert, e.g. a <meta http-equiv=...> header from server.R?
Motivation: I want to be able to download files directly into an R console session from a URL pointing at a Shiny app. So, a non-geeky user specifies their preliminary statistical model using Shiny, then a statistician downloads it into their usual working environment and takes it the rest of the way. I need to do this server-side rather than with something like javascript's window.location because javascript won't be supported client-side.
Here is the server.R
shinyServer(function(input, output, clientData) {
query <- reactive(parseQueryString(clientData$url_search));
revals <- reactiveValues();
## obtain ID from GET string
observe({revals$id <- query()$id});
## alternatively obtain ID from user input if any
observe({input$submitid; if(length(id<-isolate(input$manualid))>0) revals$id <- id;});
## update filename, path, and existance flag
observe({ revals$filename <- filename <- paste0(id<-revals$id,".rdata");
revals$filepath <- filepath <- paste0("backups/",filename);
revals$filexists <- file.exists(filepath)&&length(id)>0; });
## update download handler
output$download <- {downloadHandler(filename=function() revals$filename, content=function(oo) if(revals$filexists) system(sprintf('cp %s %s',revals$filepath,oo)))};
## render the download link (or message, or lack thereof)
output$link <- renderUI({
cat('writing link widget\n');
id<-revals$id;
if(length(id)==0) return(div(""));
if(revals$filexists) list(span('Session download link:'),downloadLink('download',id)) else {
span(paste0("File for id ",id," not found"));}});
});
Here is the ui.R
shinyUI(pageWithSidebar(
headerPanel(div("Banner Text"),"Page Name"),
sidebarPanel(),
mainPanel(
htmlOutput('link'),br(),br(),
span(textInput('manualid','Please type in the ID of the session you wish to retrieve:'),actionButton('submitid','Retrieve')))));
Update:
In trying #jeff-allen 's suggestion, I ran into another problem: how to extract the filesystem path to which the files get copied for downloading and turn it into a valid URL? It's probably possible by screwing with shell scripts and http config settings on my local host, but how to do this in a portable way that doesn't require superuser privileges and is as shiny-native as possible?
Motivation: I want to be able to download files directly into an R
console session from a URL pointing at a Shiny app.
...i.e. this amounts to a very roundabout way of trying to serve static content from a shiny app. Turns out I don't need to redirect or use downloadHandler at all. As this post on the Shiny forum says, any file I create inside the local www directory will be accessible as if it is at the root of my app directory. I.e. if I have my app do save.image(file='www/foo.rdata') then I will be able to access it from [http://www.myhost.com/appname/foo.rdata] if the app itself lives at [http://www.myhost.com/appname/]