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.
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 building a shiny app that is supposed to show a bupaR process_map, which is kind of working.
Sadly the process_map()-function returns a dgr_graph-object, which can't be rendered with the DiagrammeR::renderGrViz() or DiagrammeR::renderDiagrammeR() functions. I found a way to convert it to a grViz / htmlwidget-object with render_graph(), but this way the graph is not nicely scaled. This is especially bad since I'm dealing with very long linear graphs.
Here is a MWE:
# server.R
library(DiagrammeR)
library(bupaR)
shinyServer(
function(input, output) {
plot <- patients %>%
process_map(rankdir = "TB",
render = FALSE)
output$diagram <- renderGrViz({
render_graph(plot)
})
}
)
# ui.R
library(DiagrammeR)
shinyUI(fluidPage(
titlePanel("DiagrammeR + shiny"),
grVizOutput(outputId = "diagram")
))
Is there a better way of displaying a dgr_graph-object in shiny, that fills out the whole width of the app and not just a post-stamp size in the middle? Ideal would be something adaptive, without the need for a fixed width in pixels.
As it turns out the problem is not the render_graph-function on the Server, but rather the default setting of the renderGrViz-function in the UI. When you set it to grVizOutput(outputId = "diagram", height = "100%") it works just fine.
I am totally new to Shiny, so first, apologize my inexperience.
I am writing a dynamic report using R Markdown, and I have several plots that deserve being shown dynamically.
Let's work with the mtcars dataset, and let's create 4 plots:
plot1 <- plot(mtcars$mpg)
plot2 <- plot(mtcars$cyl)
plot3 <- plot(mtcars$hp)
plot4 <- plot(mtcars$qsec)
So, how can I create a dropdown menu with these four plots being displayed accordingly?
I mean your example is the simplest shiny example I have ever seen on stackoverflow. I suggest you take a bit of time doing the tutorial, then you try building your own app and if you're stuck come back here :)
To learn shiny I recommend Rstudio's tutorial. After learning and forgetting everything again I advise you to use the wonderful cheatsheet provided by Rstudio.
The app.r looks like this:
library(shiny)
library(plotly)
### ui.r
ui <- fluidPage(selectInput('my_dropdown','Choose Column',colnames(mtcars)),
plotOutput('my_plot')
)
### server.r
server <- function(input, output) {
output$my_plot <- renderPlot(
plot(mtcars[,input$my_dropdown],ylab=input$my_dropdown,xlab='value')
)
}
shinyApp(ui,server)
Just for the sake of completeness. This kind of graph could be created using plotly as well. The advantage is that you can use this in a standalone html. The disadvantage is that dropdowns with plotly are quite code-intensive. The tutorial for plotly is here: https://plot.ly/r/dropdowns/
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")
The actual issue I'm trying to solve: I'm creating a dashboard which will include data tables. I would like for numbers to be formatted with commas as thousands separators, but there is (apparently) an issue with the DT package when it's used with Shiny, in that the comma-separated formatting causes DT::renderDataTable to read in numbers as character, which affects how the numbers are sorted. (DT's number formatting functionality does not work with Shiny, it appears.)
Where I'm at so far: The only solution I've been able to find is to use googleVis instead of DT to create the tables. Now I'm running into a different issue (described below), but what I really care about is having data tables with comma-separated numbers that sort like numbers.
The GoogleVis issue: When I use gvisTable outside of Shiny apps, they render perfectly fine, but they do not render at all when using renderGvis and htmlOutput in Shiny. As an example, I'll borrow Example 4 from here.
Not using Shiny, my code looks like this:
library(datasets)
library(googleVis)
myOptions <- list(page='enable', pageSize=10, width=550)
Table <- gvisTable(Population,options=myOptions)
plot(Table)
Using Shiny, it's like this:
library(datasets)
library(googleVis)
library(shiny)
shinyApp(
ui = pageWithSidebar(
headerPanel("Example 4: pageable table"),
sidebarPanel(
checkboxInput(inputId = "pageable", label = "Pageable"),
conditionalPanel("input.pageable==true",
numericInput(inputId = "pagesize",
label = "Countries per page",10))
),
mainPanel(
htmlOutput("myTable")
)
),
server = function(input,output){
myOptions <- reactive({
list(
page=ifelse(input$pageable==TRUE,'enable','disable'),
pageSize=input$pagesize,
width=550
)
})
output$myTable <- renderGvis({
gvisTable(Population,options=myOptions())
})
}
)
Any help is much appreciated!
I solved my own problem. It turns out that RStudio's native browser has difficulty displaying googleVis exhibits through Shiny. All I needed to do was open it up in Firefox... I don't think I've ever felt so much "woot" and "ugh" at the same time before.