I am trying to create a shiny app using rhandsontable. I am using the code below:
library(shiny)
library(rhandsontable)
library(ggplot2)
ui = fluidPage(
rHandsontableOutput ('table'))
server = function(input, output, session) {
output$table < renderRHandsontable(mpg)}
shinyApp(ui, server)
When i run the code i get error "rendering objects from shinyoutput not allowed"
Any idea why its happening ?
This should do:
library(shiny)
library(rhandsontable)
library(ggplot2)
ui <- fluidPage(
mainPanel(
rHandsontableOutput('table')
)
)
server = function(input, output, session) {
output$table <- renderRHandsontable({
rhandsontable(head(mpg))
})
}
shinyApp(ui, server)
Related
My goal is to plot the output, a process map, onto the browser. The output plot continues to appear in the Viewer pane in RStudio.
All of the functionality works as expected and I'm able to call the appropriate data and generate a dynamic output based on the dropdown menu.
Any help would be much appreciated. Full code is below.
library(shiny)
library(bupaR)
library(pm4py)
library(reticulate)
library(processmapR)
ui <- fluidPage(
tags$h1("Process Mining"),
tags$p("The purpose of this application is to show the Process Map output"),
fluidRow(
selectInput("pm_type","Process Mining Type", c("absolute","relative"))),
fluidRow(
plotOutput("plot1"))
)
server <- function(input, output) {
selectedData <- reactive({input$pm_type})
output$plot1 <- renderPlot({
patients %>%
process_map(type = frequency(selectedData()))
})
}
shinyApp(ui = ui, server = server)
To get output of process_map in shiny you have to use GrViz functions from DiagrammeR.
library(shiny)
library(bupaR)
library(pm4py)
library(reticulate)
library(processmapR)
library(DiagrammeR)
ui <- fluidPage(
tags$h1("Process Mining"),
tags$p("The purpose of this application is to show the Process Map output"),
fluidRow(
selectInput("pm_type","Process Mining Type", c("absolute","relative"))),
fluidRow(
grVizOutput("plot1"))
)
server <- function(input, output) {
selectedData <- reactive({input$pm_type})
output$plot1 <- renderGrViz({
patients %>%
process_map(type = frequency(selectedData()))
})
}
shinyApp(ui = ui, server = server)
The given R shiny script creates a simple data table as in the snapshot with an actionButton in the center. I want to place the button a little below it's current position such that it is in perfect horizontal inline position to the search bar. Thanks and please help.
library(DT)
library(shiny)
library(shinyBS)
library(rpivotTable)
library(bupaR)
ui <- basicPage(
h2("The mtcars data"),
column(5,offset = 5,actionButton("CR1_S1", "Button")),
dataTableOutput("mytable1")
)
server <- function(input, output) {
output$mytable1 <- DT::renderDataTable({
DT::datatable(iris)
})
}
shinyApp(ui, server)
You can put the button inside the datatable in this way:
ui <- basicPage(
h2("The mtcars data"),
actionButton("CR1_S1", "Button"),
DTOutput("mytable1")
)
server <- function(input, output) {
output$mytable1 <- renderDT({
datatable(iris, callback = JS("$('div.button').append($('#CR1_S1'));"),
options = list(
dom = '<"row"<"col-sm-4"l><"col-sm-4 text-center"<"button">><"col-sm-4"f>>tip'
))
})
}
shinyApp(ui, server)
Sometimes we'd like to put content in a uiOutput/renderUI. But this doesn't always work. For instance, the example below. In my mind, code#1 and code#2 should give me the same GUI. However, code#2 doesn't work as expected. Can anyone tell me the reason? Thanks!
Code#1:
library(shiny)
ui <- navbarPage("test",
navbarMenu("More",
tabPanel("Table"
)
)
)
server <- shinyServer(function(input, output, session) {
})
shinyApp(ui = ui, server = server)
Code#2:
library(shiny)
ui <- navbarPage("test",
uiOutput("ui_data")
)
server <- shinyServer(function(input, output, session) {
output$ui_data <- renderUI({
navbarMenu("More",
tabPanel("Table"
)
)
})
})
shinyApp(ui = ui, server = server)
In the second example, uiOutput wraps the content of navbarMenu inside a div with the class "shiny-html-output". Divs of this class are however not allowed as an argument for navbarPage. AFAIK, there are two ways to resolve this
The first is to create the whole navbarPage on the server-side.
library(shiny)
ui <- uiOutput("page")
server <- shinyServer(function(input, output, session) {
output$page <- renderUI({
navbarPage("test", navbarMenu("More", tabPanel("Table")))
})
})
shinyApp(ui, server)
The other one is to only create the contents of the tabPanel in the server
library(shiny)
ui <- navbarPage(
"test",
navbarMenu("More", tabPanel("Table", uiOutput("tab_content")))
)
server <- shinyServer(function(input, output, session) {
output$tab_content <- renderUI({
"Some content"
})
})
shinyApp(ui = ui, server = server)
Please try to set your working directory first like example below.
setwd("c:/Users/ID/Desktop/folder")
You should get working directory with location of ui.R and server.R.
I am trying to build shiny dashboard application.
Within the application, I need to render a table dynamically.
When I load the application, I am not receiving the tabular output.
I have split the code into three files: global.R, ui.R, and server.R
global.R
my_data <- head(mtcars)
ui.R
tabItem(tabName = "impRels",
fluidRow(
box(DT::dataTableOutput("table1"))
)
)
server.R
output$table1 <- DT::renderDataTable({
datatable(my_data)
})
Simplified, as a start. You might want to work on your UI, though.
library(shiny)
library(DT)
my_data <- head(mtcars)
ui <- shinyUI(
fluidPage(
fluidRow( dataTableOutput("table1") )
)
)
server <- shinyServer(function(input, output, session){
output$table1 <- renderDataTable({ datatable(my_data) })
})
shinyApp(ui=ui, server=server)
I'm experimenting a Shiny App to show dynamic contexts, but I cannot get renderDataTable working into a renderUi component.
Below two simple replicable tests: the first one is not working, the second one without renderUi works fine, of course.
What is the conceptually difference between this two, and why the first one cannot work in Shiny?
This one not works: note that the uiOutput myTable, contains two reactive component, a selectInput and a renderDataTable, but only the selectInput is rendered.
library(shiny)
runApp(list(
ui = fluidPage(
fluidRow(h2("where is the table?")),
uiOutput('myTable')
),
server = function(input, output) {
output$myTable <- renderUI({
fluidPage(
fluidRow(selectInput("test", "test", c(1,2,3))),
fluidRow(renderDataTable(iris))
)
})
}
))
This is fine, both selectInput and renderDataTable are rendered:
library(shiny)
runApp(list(
ui = fluidPage(
fluidRow(h2("where is the table?")),
fluidRow(selectInput("test", "test", c(1,2,3))),
fluidRow(dataTableOutput('myTable'))
),
server = function(input, output) {
output$myTable = renderDataTable(iris)
}
))
How to get the first scenario working?
Thanks.
EDITING after Yihui comment (thanks Yihui):
In renderUi has to be used some ui function, and not some render function:
changed the sample code in the correct way, the result does not change: still no data is shown.
library(shiny)
runApp(list(
ui = basicPage(
uiOutput('myTable')
),
server = function(input, output) {
output$myTable <- renderUI({dataTableOutput(iris)
})
}
))
EDIT n.2
Just solved, got it working so:
library(shiny)
runApp(list(
ui = fluidPage(
mainPanel(
uiOutput('myTable')
)
),
server = function(input, output) {
output$myTable <- renderUI({
output$aa <- renderDataTable(iris)
dataTableOutput("aa")
})
}
))
I have to save the renderTableOutput in a output variable first, and then feeding it to dataTableOutput.
Thanks for pointing me to: here
It would be clearer if you split the part of datatable generation and ui generation :
library(shiny)
runApp(list(
ui = fluidPage(
mainPanel(
uiOutput('myTable')
)
),
server = function(input, output) {
output$aa <- renderDataTable({iris})
output$myTable <- renderUI({
dataTableOutput("aa")
})
}
))