I'd like to deploy a web site using R shiny with a googleVis motion chart,
but when running the app, the motion chart showed up in another window in IE browser.
I'm wondering how the motion chart can show up together along with the R shiny.
Thanks in advance.
server.R
shinyServer(function(input, output) {
project_sub<-subset(project_all, select=c("name", "generation",
"man_cost", "quantity"))
motionchart2<-gvisMotionChart(project_sub, "name", "year2")
output$view_gviz <- renderGvis
({
plot(motionchart2)
})
})
ui.R
shinyUI(fluidPage(
titlePanel("Analysis of Project NRE"),
mainPanel(
h1("Motion Chart"),
h4("A Motion Chart is an alternative to providing a quick visual
overview ofprojects."),
plotOutput("view_gviz")
)
))
I ran into this problem. Try this in your ui.R
# googleVis needs htmlOutput not usual PlotOutput
htmlOutput("view_gviz")
Related
I'm trying to plot the outcomes of EDA on to Shiny App, I have been using DataExplorer library for the same and i'm able to perform operations on rmarkdown notebook. I was thinking to integrate the plots to shiny app using the below code but i'm running into errors,Can you please assist me in this regard and also suggest me if there is a way possible to achieve this.
UI part
library(shiny)
library(DataExplorer)
fluidRow(width=12,
column(12,plotOutput("struct"))
)
Server block
df<-read.csv("/path/to/csv/file.csv")
output$struct<-renderPlot({
req(df)
plot_str(df)
})
Thanks for the help in advance
DataExplorer::plot_str by default prints a networkD3::diagonalNetwork, however, it returns a list.
If you want to render the diagonalNetwork object in shiny you'll need to use networkD3::renderDiagonalNetwork. Please check the following:
library(shiny)
library(DataExplorer)
library(datasets)
library(networkD3)
# DF <- read.csv("/path/to/csv/file.csv")
DF <- mtcars
ui <- fluidPage(
fluidRow(column(12, diagonalNetworkOutput("struct")))
)
server <- function(input, output, session) {
output$struct <- renderDiagonalNetwork({
req(DF)
diagonalNetwork(plot_str(DF, print_network = FALSE))
})
}
shinyApp(ui, server)
I'm looking at implementing 3D interactive plots in my shiny App, and so far I've been using plotly. However, plotly has one major disadvantage, it's extremely slow when rendering.
I've done checks, and the whole creation of updated outplot$plot <- renderPlotly ({.....}) and plotlyOutput("plot") takes less than 0.5 seconds, despite the large data set involved. This is a know issue for years but still seems to be current.
Hence, I'm looking to use a package called car, also because it has many options, some which I particularly want that are not available in other packages. Info on the car package is here: http://www.sthda.com/english/wiki/amazing-interactive-3d-scatter-plots-r-software-and-data-visualization
The problem is that it renders in a separate popup window rather than inside the shiny app, and I want to have it inside it, or even better, add a button that allow the user to have it as a popup, but only when asked. However, i can't figure out how to jam the bugger into the actual shiny page.
Here is my minimal example with a single text element and the graph code that (in my case) keeps appearing in a separate window rather than in the app.
install.packages(c("rgl", "car", "shiny"))
library("rgl")
library("car")
library(shiny)
cars$time <- cars$dist/cars$speed
ui <- fluidPage(
hr("how do we get the plot inside this app window rather than in a popup?"),
plotOutput("plot", width = 800, height = 600)
)
server <- (function(input, output) {
output$plot <- renderPlot({
scatter3d(x=cars$speed, y=cars$dist, z=cars$time, surface=FALSE, ellipsoid = TRUE)
})
})
shinyApp(ui = ui, server = server)
There is also this package, scatterplot3d but that's not interactive
http://www.sthda.com/english/wiki/scatterplot3d-3d-graphics-r-software-and-data-visualization
And there are some RGL packages but they have the same issue (seperate window) and don't offer the options I am lookign for.
You need to use an rglwidget which takes the last rgl plot and puts in in an htmlwidget. It used to be in a separate package, but it has recently been integrated into `rgl.
Here is the code to do this:
library(rgl)
library(car)
library(shiny)
cars$time <- cars$dist/cars$speed
ui <- fluidPage(
hr("how do we get the plot inside this app window rather than in a popup?"),
rglwidgetOutput("plot", width = 800, height = 600)
)
server <- (function(input, output) {
output$plot <- renderRglwidget({
rgl.open(useNULL=T)
scatter3d(x=cars$speed, y=cars$dist, z=cars$time, surface=FALSE, ellipsoid = TRUE)
rglwidget()
})
})
shinyApp(ui = ui, server = server)
Yielding this:
I used googleVis to generate a chart object (x) then outputted it as:
cat(x$html$chart, file="y.html")
How do I input this raw .html file into a Shiny server.R and then get it to render properly on the ui? I can't find anything. I've tried with
y <- readLines("y.html")
output$Plot = renderHTML(HTML(y))
and
shinyUI(fluidPage(
titlePanel(""),
sidebarLayout(
sidebarPanel(
...
),
mainPanel({
htmlOutput("Plot")
}
)
)
))
but this just generates a blank area. I omitted sidebarPanel because I know that works with my rendergVis() code that I was running.
Anyone know how to do what I'm trying to do?
I'm new to Shiny and R in general and could do with some help!
I've been trying to get some googleVis outputs into Shiny without success. I can get gvis outputs for bubble, motion and scatter charts directly in R but not in a shiny app.
I've checked reference code from Mages and others but I don't get an output chart in Shiny.
I've stripped it back to its most basic but can't get the visualisation. Is there anyone who could give me a pointer on what I am doing wrong?
Thanks!
#UI.R
library(shiny)
library(googleVis)
shinyUI(fluidPage(
titlePanel("GoogleVis example"),
sidebarLayout(
sidebarPanel(
h4("GoogleVis and Shiny")
),
mainPanel(
htmlOutput("bubble")
)
))
)
#Server.R
library(shiny)
library(googleVis)
shinyServer(function(input, output, session){
Newyork=read.csv("data/Newyork.csv")
output$bubble<- renderGvis({
gvisBubbleChart(Newyork, idvar="County", xvar="Population", yvar="Crime.Rate")
})
})
I came along with this problem, that rCharts plot won't show in my shiny app. I found this example which perfectly suits my needs. Even though this chart works perfectly while just plotting in R, in shiny it is an blank page.
I am not sure what is wrong with it. Firstly, I am not sure if I am choosing right library in showOuput(), but I didn't find any better solution.
I am trying to plot it more sophisticated app, however, I reproducing my simple app code below of server:
server.R
library(rCharts)
library(reshape2)
options(RCHART_WIDTH = 1700)
meansconferences <-read.csv("https://raw.github.com/patilv/ESPNBball/master/meansconferences.csv")
shinyServer(function(input, output) {
output$test <- renderChart({
meltmeansconferences=melt(meansconferences[-c(1,10:14)], id.vars=c("Conference","Year"))
d1=dPlot(y="Year", x="value",data=meltmeansconferences, groups="variable",type="bar")
d1$yAxis(type="addCategoryAxis", orderRule="Year")
d1$xAxis(type="addPctAxis")
return(d1)
})
}
)
And ui:
ui.R
options(RCHART_LIB = 'dimple')
shinyUI(pageWithSidebar(
headerPanel("rCharts and shiny"),
sidebarPanel(),
mainPanel(
h4("Graph here"),
showOutput("test","dimple")
)
))
EDITED: I am using R version 3.0.2 and rCharts 0.4.2 shiny 0.8.0.99
If you have any ideas, just let me know.
Thank you in advance!
Posting my comment as an answer so that this question can be closed
Switch to renderChart2 or explicitly set d1$set(dom = "test") if you are using renderChart. I would recommend renderChart2, since I hope to combing the two functions in the next version.