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?
Related
I am finally trying to make a Shiny app. I am trying to upload a .xlsx file to the app, and then apply some analysis and download the output as a separate .xlsx file. The code for analysis and taking output works when run directly outside Shiny and I use it on daily, so I am simply trying to call it via source and save the duplicated work. Here is what I am trying with Shiny.
I was having problems in calling the file from the W2S.R script, while avoiding errors. I found a way to avoid the errors. The below code is a barebones model of that. However, now I cannot get the actual input to work (Output works fine, one table output on-screen and one XLSX output off-screen).
I am using W2S <- input$W2S1 inside W2S.R script, but it is not recognising the variable input, which it does if used in the server function directly. How do I get it to work inside the script? Or is there any other workaround?
library(shiny)
ui <- fluidPage(
titlePanel(h1("Goods In Transit Analysis", align="center")),
sidebarLayout(
sidebarPanel(
fileInput("W2S1", label="Select GIT W2S file")
),
mainPanel(
tableOutput("contents")
)
)
)
server <- function(input, output) {
output$contents <- renderTable(if(is.null(input$W2S1)){return(NULL)}
else{source("./W2S.R")})
}
shinyApp(ui = ui, server = server)
I will update once I get the input to work. Please help.
EDIT: Made some progress, as noted above. So updated the new code.
Finally nailed it. I needed an observe function and use the $datapath argument.
library(shiny)
ui <- fluidPage(
# Application title
titlePanel(h1("Goods In Transit Analysis", align="center")),
# Sidebar iputs
sidebarLayout(
sidebarPanel(
fileInput(inputId="W2S", label="Select GIT W2S file")
),
# On Screen output
mainPanel(
h3(textOutput("filePath")),
tableOutput("contents")
)
)
)
# Underlining code for output
server <- function(input, output) {
observe({
source("./Code/W2S.R")
W2S <- input$W2S
output$contents <- renderTable(if(is.null(W2S)){return(NULL)}
else{W2S_F(W2S$datapath)})
})
}
# Run the application
shinyApp(ui = ui, server = server)
I have a Shiny application that requires the user to upload multiple small text files, I do this with fileInput. When I upload multiple files, the progress bar seems to half reset after each file is uploaded in turn. This looks very messy and I'd prefer it if the bar simply showed how many files had finished uploading rather than the progress of any individual file.
Here is a gif of the behavior:
My question is: Is there a way using base Shiny to change the behavior of the upload progress bar for fileInput? And if not, are there any other packages that could be used?
Here is an example of using fileInput
library(shiny)
ui <- fluidPage(
titlePanel("File Input Progress Bar Demo"),
fileInput(
inputId = "MyFiles",
label = "Upload multiple files",
multiple = T
),
mainPanel()
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
D3partitionR has some fantastic visualisations for hierarchical and sequential data, however it seems to have a major flaw in Shiny.
The D3partitionROutput function (& renderD3partitionR) don't update the plotted object when the output object is updated.
The functions work perfectly on first execution of a graph however the plotted objects can't be reactively updated.
Does anyone know of a fix or workaround as I really like this package's visualisations?
library(shiny)
library(D3partitionR)
path_in=list(list("A","B","C","D"),list("A","B","F","G"),list("A","D"),list("A","B","END"))
value_in=c(15,29,21,34)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("type_in",
"Plot type:",
choices = c('circleTreeMap', 'partitionChart', 'treeMap')
)
),
# Show a plot of the generated distribution
mainPanel(
D3partitionROutput("part_out")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$part_out <- renderD3partitionR({
type = input$type_in
D3partitionR(data=list(path=path_in,value=value_in)
, type = type)
})
}
# Run the application
shinyApp(ui = ui, server = server)
Update:
I found a similar bug here in Rwordcloud that was resolved by modifying the "render" function in Rwordcloud.js. I looked into renderValue in D3partitionR.js and the function doesn't take an input of 'instance' (as is done in Rwordcloud.js) so it seems it doesn't know when to delete / refresh renderValue. I'm an R guy (and have no js experience) so I don't know how the renderValue function should be changed in D3partitionR.js however I'm pretty sure this is the source of the problem.. Help!
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 have a Shiny application and an R Script that I'd like to embed into my Shiny app. The script outputs a ggplot and I am not sure how to make it appear in my Shiny App. I've excluded some of the extraneous code. The script is successfully called, and the variables are stored in my workspace, but then nothing is displayed.
I've included the following in my server.R file:
##server.R##
source("heatmap.R", local=TRUE)
output$heatmap <- renderPlot ({
heatmapOutput
})
##ui.R##
shinyUI(fluidPage(
column(10, plotOutput("heatmap"))
),
Your output must be inside a shinyServer:
shinyServer(function(input, output) {
output$heatmap <- renderPlot ({ heatmapOutput })
}