Google Charts on Shiny Server not work - shiny-server

I downloaded an example from website, which is about how to use googleVis on shiny.
It works well when running locally, however, when I deploy it on shiny server, it doesn't work any more.
Shiny server is running on Red Hat Linux, and I have deployed some other programs on server, and they all works, except this one.
server.R
library(googleVis)
library(shiny)
shinyServer(function(input, output) {
datasetInput <- reactive({
})
Bubble <- gvisBubbleChart(Fruits, idvar="Fruit",
xvar="Sales", yvar="Expenses",
colorvar="Year", sizevar="Profit",
options=list(
hAxis='{minValue:75, maxValue:125}'))
plot(Bubble)
})
ui.R
shinyUI(pageWithSidebar(
headerPanel("Example 1: scatter chart"),
sidebarPanel(
),
mainPanel(
htmlOutput("view")
)
))

Related

How to associate a Jupyter Workspace Custom Container with it's Vertex AI Workbench instance

I have multiple User Managed Vertex AI Workbench instances running in my GCP Project.
Each can run one or more Jupyter Workspaces by clicking OPEN JUPYTERLAB. Each Jupyter lab opens in a new browser tab.
From one of the Jupyter lab tabs, how can I tell which workbench instance or VM is hosting it?
EDIT: The first answer by #kiran mathew is not working for me because I have a custom docker container and that solution returns the hostname of the container which is not set to the Workench instance name. I changed the title of the question to be specific to custom containers.
Python code:
import socket
instance_name = socket.gethostname()
print(instance_name)
I have two notebooks stacckkk and stackoverflow2 . When I ran the above code in these two notebook individually I got the below results.
Result:
1st Notebook
2nd Notebook
Using the URL solution in the comment by #KiranMathew, here is a function to return the workbook name that works with custom docker containers.
def get_workbook_name():
url = "http://metadata.google.internal/computeMetadata/v1/instance/name"
req = urllib.request.Request(url)
req.add_header("Metadata-Flavor", "Google")
workbook_name = urllib.request.urlopen(req).read().decode()
return workbook_name
Still anticipating a simpler approach will be available as foreshadowed by #gogasca
You can also get the project id with: http://metadata.google.internal/computeMetadata/v1/project/project-id

Running a salix webApp through an IDE menu

I have a bit of code that creates a salix webapp and runs it from an IDE popup menu by making use of util::Webserver. In order to allow for the command to be used multiple times, I try to shutdown any existing webserver at that address first but it doesn't seem to be working. No matter what it always comes up with an illegal argument error stating "shutdown" not possible.
void run_game(Tree t, loc s){
t = annotate(t);
PSGAME g = ps_implode(t);
Checker c = check_game(g);
Engine engine = compile(c);
loc host = |http://localhost:9050/|;
try { util::Webserver::shutdown(host);} catch: ;
util::Webserver::serve(host, load_app(engine)().callback, asDaemon = true);
println("Serving content at <host>");
}
What I expect to happen is that the first time this function it run, shutdown throws an error that is silenced because no webserver exists and then serve starts the webserver. If the user tries to run the function again then shutdown successfully runs, clearing the address bind and serve binds successfully to the address.
What actually happens the second time, is that shutdown still errors, the error is silenced and then serve complains that the address is already in use.
I'm looking for any solution that would allow me to start a salix app through the IDE's popup menu (previously registered) at the same address.
PS_contributions =
{
PS_style,
popup(
menu(
"PuzzleScript",
[
action("Run Game", run_game)
]
)
)
};
registerContributions(PS_NAME, PS_contributions);
Right; we ran into similar issues and decided to special case actions that run web apps. So we added this:
data Menu = interaction(str label, Content ((&T <: Tree) tree, loc selection) server)
See https://github.com/usethesource/rascal-eclipse/blob/bb70b0f6e8fa6f8c227e117f9d3567a0c2599a54/rascal-eclipse/src/org/rascalmpl/eclipse/library/util/IDE.rsc#L119
Content comes from the Content module which basically wraps any Response(Request) servlet.
So you can wrap your salix webApp in a Content and return it given a current selection and the current tree.
The IDE will take care to start and also shutdown the server. It does that every time an interaction with the same label is created or after 30 minutes of silence on the given HTTP port.

How do I connect xterm.js(in electron) to a real working command prompt?

I've dug myself into a deep rabbit hole trying to find out what the title says. If you're confused about what this question is, I'll give a more detailed explanation: Have you ever seen the VSCode Terminal? or Terminus? Well I want to do what those applications do. I have an electron app, and for the users convenience I want to include a command prompt of some sorts into it. I've looked in to xterm.js, but I can only find examples of things like SSH, not a direct link to a console hosted on the system. What I'm asking is how do I connect xterm.js(in electron) to a real working command prompt? I've seen programs able to interact with cmd.exe such as Windows Terminal. I'll use it as an example.
Image taken from process hacker
In the attached photo you can see three processes. WindowsTerminal.exe, OpenConsole.exe, and cmd.exe. After digging around in the source code of Windows Terminal, I can see the OpenConsole.exe gets started with every instance of a cmd that you make. So I assume that is the program that's interacting with cmd.exe. Now I know that Windows Terminal is made using UWP but you can see similar things happening with VSCode(I opened a bunch of terminals to demonstrate)
here is another post with a similar question, but with no answers. I hope this one gains some traction.
So if you can answer, thanks. If you got sidetracked a bit, remember my question: How do I connect xterm.js(in electron) to a real working command prompt?
Sorry if you couldn't understand my wording, im not very good at this :P
The following video was helpful for me. Shortly, you need to :
install node-pty and electron-rebuild packages (additional to the xterm)
Place the following codes to appropriate process files
In the main process (main.js):
const os = require('os');
const pty = require('node-pty');
var shell = os.platform() === "win32" ? "powershell.exe" : "bash";
var ptyProcess = pty.spawn(shell, [], {
name: 'xterm-color',
cols: 80,
rows: 24,
cwd: process.env.HOME,
env: process.env
});
ptyProcess.on("data", (data) => {
mainWindow.webContents.send("terminal-incData", data);
});
ipcMain.on("terminal-into", (event, data)=> {
ptyProcess.write(data);
})
In the renderer process:
const Terminal = require('xterm').Terminal;
const FitAddon = require('xterm-addon-fit').FitAddon;
const term = new Terminal();
const fitAddon = new FitAddon();
term.loadAddon(fitAddon);
// Open the terminal in #terminal-container
term.open(document.getElementById('terminal-container'));
term.onData(e => {
ipcRenderer.send("terminal-into", e);
} );
ipcRenderer.on('terminal-incData', (event, data) => {
term.write(data);
})
// Make the terminal's size and geometry fit the size of #terminal-container
fitAddon.fit();
run electron-rebuild command if you get an error.
You might get the following errors when you try to install electron-rebuild package:
Solution for MAC: error: no template named 'remove_cv_t'.
Solution for Windows: gyp ERR! find Python
I figured it out, code on github: https://github.com/77Z/electron-local-terminal-prototype

Server Code for Shiny-Server for a Specific App is not showing any of the Dataframes

So the ui.R file is working perfectly. However, the server.R is what I suspect may be causing the issue here. The intended behavior is that I have data frames display above the embedded HTML charts on each one of my pages. However, the data frames are not generated. The intended goal is to use the google sheets package, read a google sheet, and then morph it into a data frame exposed on R Shiny.
I have tried placing the data frame function and definition above and below within the ui.R and the server.R. However, I am not getting any return on any of the output.
This is for a Shiny-Server hosted on Ubuntu 16.04 Server.
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(shinydashboard)
library(googlesheets)
library(googleCharts)
library(googleAuthR)
library(stats)
library(searchConsoleR)
library(googleAnalyticsR)
library(httr)
library(dplyr)
library(plyr)
library(mosaic)
library(DT)
library(httpuv)
library(htmltools)
# Google Sheets for Synced Keys with Data Master
# ===============================================
handover <- gs_key("1Wu8gJ#$%%#$%%###$##$#%###$%##%-VVHcB8c")
for_gs_sheet <- gs_read(handover)
str(for_gs_sheet)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
google_app <- oauth_app(
"google",
key = "3901########################m",
secret = "b#########################z"
)
#oauth2.0_token(google_app)
## ---------- Google Authentication ---------- ##
gs_auth(token = NULL ,new_user = FALSE,
key = getOption("################.com"),
secret = getOption("##############Ka5mz"),
cache = getOption("googlesheets.httr_oauth_cache"), verbose = TRUE)
for_gs_sheet <- gs_read(handover)
str(for_gs_sheet)
output$mytable = DT::renderDataTable({
df <- gs_read(handover)
})
})
The actual results should show output as related to the DT package. However, the data table is not being processed and/or is not made visible when called in the server output.
This stems from a service token issue.
The best way is to just create a service token and session that maintains an open connection and refreshes the token.
I fixed this issue by backing the token directly into the app via JSON and having the app call the JSON file within the directory the shiny app was stored in under the /srv/ directory. You can download a copy of the service account information and store it in the working directory of the app:
root#miradashboard1:/srv/shiny-server/Apps/CSM# ls
miradashboard-f89f243d0221.json server.R ui.R
Then make sure you call the service token within the server.R and ui.R.
service_token <- gar_auth_service(json_file="/srv/shiny-server/Apps/CSM/miradashboard-f89f243d0221.json")

What would cause InternetExplorerMedium to work on one machine but not another?

I have a VBA script in Access that logs onto a website and downloads some data, I built it using a laptop and use the code of
Dim objIE As InternetExplorerMedium 'special object variable representing the IE browser
Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element
Dim element As HTMLLinkElement
Set objIE = New InternetExplorerMedium
On Error GoTo Errorhandler
objIE.Visible = False
DoCmd.Hourglass (True) 'navigate IE to this web page
objIE.navigate www.google.com ' google just for example
Then it inputs the login info into the proper boxes and logs in.
Which works fine, however I installed this front end on another user's PC and it no longer works, it just opens the page but fills in no info.
However, if I change,
Set objIE = New InternetExplorerMedium
to
Set objIE = CreateObject("InternetExplorer.Application")
then it works on their PC. But this change does not work on my laptop.
What would cause this issue and how could I standardize this so I can install on any windows machine without worry of this occurring.
Notes:
We are both on the company LAN, and both are running windows 10 Home.
It was something incredibly simple, I just had to add the website I was accessing as a trusted site in Internet Explorer.

Resources