I have a file file.RData with one of the data frames containing values with Swedish characters.
When loading file.RData in the Shiny app, it works fine on the local Windows machine, but when I move it to Ubuntu server and run it in RStudio Server: I get Error : invalid multibyte string
I changed Ubuntu's locale to sv_SE.UTF-8, rebooted and I still get the error. I've been looking at other similar problems link1 link2 , but don't know how to adapt it to my particular situation.
Is there any way to make my Shiny app work on Shiny server and keep file.RData with Swedish characters?
Here's a sample of my code in app.R:
library(shiny)
library(ggplot2)
library(lubridate)
(WD <- getwd())
if (!is.null(WD)) setwd(WD)
load ("file.RData")
server<-function(input,output){
.......
}
ui<-fluidPage(
.......
)
shinyApp(ui = ui, server = server)
I managed to convert the columns of the data frames, which had Swedish characters, by adding the following code after loading the file.RData:
load ("file.RData")
Encoding(df1$TEAM)<-"latin1"
Encoding(df2$TEAM)<-"latin1"
Encoding(df3$Team)<-"latin1"
Related
I want to start with translation in R Shiny. At the very beginning, I am creating the simplest app in Shiny and trying to translate it. But I get the following error:
Warning in load_local_config(translation_csv_config) :
You didn't specify config translation yaml file. Default settings are used.
Error in multmerge(all_files, sep) :
Key translation is not the same in all files.
Even when I comment all the app, just running the first line for defining the translation gives me this error.
I have created a csv file for translation.
The code is:
library(shiny)
library(shiny.i18n)
i18n <- Translator$new(translation_csvs_path = "translation_no.csv")
i18n$set_translation_language("en")
ui <- fluidPage(p(i18n$t("Hello")))
server <- function(input, output) {}
shinyApp(ui, server)
I have saved the csv file in the same directory as my working directory. The csv file is:
en,no
Hello,Hei
I have leaflet map in shiny dashboard with points. Clicking on some point, you will get text string from one column of main df botsad.final and subset of data from the SAME df, that should appear in the table below the map.
So:
1. Locally both text and table appear fine.
2. In production through shinyapps.io, text appears good, but table doesnt work. It produces error.
3. The df botsad.final is in directory of project and is same for textOutput (working) and tableOutput (working only locally).
Where is an error for deploying?
There is a part of server.R related to tableOutput. ui.R is here.
# Make a table with ecosystem services
output$table <- renderTable({
if (is.null(data_of_click$clickedMarker)) {
return(NULL)
}
return(
subset(botsad.final %>%
dplyr::select(7:12, 14),
id == data_of_click$clickedMarker$id
)
)
}, na = '-', bordered = T)
Are you receiving any error messages in the logs? I have not worked with leaflet maps in R, but I have deployed some applications to shinyapps.io. Please forgive my possibly unhelpful answer.
I had a look through the code, but could not run it (I think because I did not have the data).
My guess is that two things could be going wrong:
(1) the data is not being copied to the server. When you are deploying to R shiny, is the data in a file being deployed?
(2) the data is not being read on the server. Are you reading in the data in a global.R file or something?
If you are sure the data is on there, share what ever the logs are telling you.
Anyone run in to his problem? I have a shiny app that uses SQL files to import data from MS SQL server using the RODBC package. I've narrowed down the problem to here in the server.R file:
ch <- odbcConnect(dsn = xxxxxx)
iQry <- readChar("LeaderDashInd.sql", file.info("LeaderDashInd.sql")$size, T)
oQry <- readChar("LeaderDashOrg.sql", file.info("LeaderDashOrg.sql")$size, T)
iDat <- sqlQuery(channel = ch, query = iQry, stringsAsFactors = F)
oDat <- sqlQuery(channel = ch, query = oQry, stringsAsFactors = F)
odbcClose(ch)
# PREPROCESSING --------------------------
cy <- max(iDat$CampYear)
The app stops at the last line above and gives... Error in iDat$CampYear : $ operator is invalid for atomic vectors. I know this chunk is the problem because when I have the same app run off imported csv files, it works.
A couple things to note:
This code runs first in the server.R file outside the shinyServer function.
The app runs fine when launched from my workstation through R Studio. It only stops working when run on our Shiny Server installation.
Shiny packages are up to date and shiny server is a recent install.
Any thoughts?
FYI... changing the SQL query to a stored procedure and then calling the stored procedure with RODBC::sqlQuery fixed the problem. The $ operator invalid error was coming up because the query was not running and returning an empty vector.
Still doesn't explain why the stand alone query using readChar doesn't work in Shiny Server but hey... its a fix.
I have a list of 4 large dataframes (size 5.9MB compressed) in an Rdata file (dtall.RData) that I am trying to read into my server.R function using the code provided below, but get "ERROR: [on_request_read] connection reset by peer" error message" and the file is read as a single character "dtall"
When I separately load the dtall.RData into r global environment the app runs locally. But as soon as I clear the dtall.RDdata file from the global environment and try to get the app to load it and run I get the error message above.
I have tried using readRDS, but that does not work either, I get error message:
"Error in readRDS("data/dtall.RData") : unknown input format
The file dtall.RData loads correctly outside the shiny scripts by using function load("data/dtall.RData"
Below is the code of my server.R function
server.R
predictor <-source("predictor.R")
dtall <- load("data/dtall.RData")
shinyServer(function(input, output) {
wordPrediction <- reactive({
text <- input$input
wordPrediction <- predictor(text)})
output$Prediction <- renderPrint(wordPrediction())
})
Thank you in advance for your help!
I am trying to publish an Shiny app at the moment but I am but after the deployment is completed an the app is loaded in the window, I get an error message of ERROR: object 'inData' not found.
In srcfile.R I am loading a .csv file which creates inData and then doing some analysis which I will use in Shiny to plot. This is my first time actually uploading an app to the server so I am unsure whether the issue is with the app really not finding the input inData or there is another error somewhere and this error message is thrown up. I have srcfile.R in the folder I uploaded as well as the .csv file that reads from.
library(shiny)
library(datasets)
library(ggplot2)
source("srcfile.R")
###########Shiny Starts here#########
shinyServer(function(input, output) {
options(scipen=5)
switcher <- function(x) {
if(x=="dis"){
#more code below of course.......
I have seen that relative pathways are always recommended but maybe I should try an absolute pathway.