shinyMobile icon indicating copy to clipboard operation
shinyMobile copied to clipboard

Rendering table

Open PatrickMasn opened this issue 2 years ago • 2 comments

Maybe because I'm new (I just learnt to code R, and shiny apps two days ago) but for some reason I'm unable to get the simplest table/graph to be rendered in the shinyMobile app. I just get an empty f7card where the data should be (the rest of the the tabs and features display correctly)

What is not working? Could someone provide a working example code?

I'm coding it with R studio server on chrome.

Thanks and great job!

This is my code:


library(shiny)
library(shinyMobile)
ui <- f7Page(
    title = "My app",
    options = list(
        theme = c("ios", "md", "auto", "aurora"),
        dark = FALSE,
        filled = TRUE,
        color = "#007aff"),

    f7SingleLayout(
        navbar = f7Navbar(
            title = "f7Table"
        ),
        f7Tabs(
            animated=TRUE,
            f7Tab(
                tabName = "Tab1",
                active= TRUE,
                icon = f7Icon("layers_alt"),

                f7Card(
                    title = "Table",
                    dataTableOutput("table")
                )
            )
        )
    )
)
server <- function(input,output,session){
    output$table <- renderDataTable(iris)
    }
shinyApp(ui=ui, server=server)

image

PatrickMasn avatar Aug 13 '21 12:08 PatrickMasn

Your code works for me on the vanilla RStudio browser and on Chrome locally. I am using data.table_1.14.0 and shinyMobile_1.0.0.9001. Note though that DT is not fully compatible with shinyMobile, e.g., https://github.com/RinteRface/shinyMobile/issues/119.

You can use f7Table instead, but it is much less cutomizable.

Tixierae avatar Oct 19 '21 08:10 Tixierae

I am trying to use ShinyMobile for the first time, and have literally cut and pasted the above code to try and get something initially working, to help with my learning. However, that code will NOT display the table (as per the original user reported). What is the issue here, why will the table not display ?

I also have some other code, that i have used (see below), which does NOT display the tables etc (ie. anything calling the plotOutput command to then display a table, does NOT display anything ??). Any help as to why the plots are not displaying would be much appreciated ...

library(dplyr)
library(ggplot2)

library(shiny)
library(shinyMobile)
shiny::shinyApp(
    ui = f7Page(
        title = "My app",
        f7SingleLayout(
            navbar = f7Navbar(
                title = "Standalone tabs",
                hairline = FALSE,
                shadow = TRUE
            ),
            f7Tabs(
                id = "tabs",
                style = "strong", animated = FALSE, swipeable = TRUE,
                f7Tab(
                    title = "Tab 1",
                    tabName = "Tab1",
                    icon = f7Icon("envelope"),
                    active = TRUE,
                    f7Shadow(
                        intensity = 10,
                        hover = TRUE,
                        f7Card(
                            title = "Card header",
                                  f7Stepper(
                                "obs1",
                                "Number of observations",
                                min = 0,
                                max = 1000,
                                value = 500,
                                step = 100
                            ),
                            print("starting plot"),
                            plotOutput("distPlot")
                        )
                    )
                ),
                f7Tab(
                    title = "Tab 2",
                    tabName = "Tab2",
                    icon = f7Icon("today"),
                    active = FALSE,
                    f7Shadow(
                        intensity = 10,
                        hover = TRUE,
                        f7Card(
                            title = "Card header",
                            f7Select(
                                inputId = "obs2",
                                label = "Distribution type:",
                                choices = c(
                                    "Normal" = "norm",
                                    "Uniform" = "unif",
                                    "Log-normal" = "lnorm",
                                    "Exponential" = "exp"
                                )
                            ),
                            uiOutput("distPlot2")
                        )
                    )
                ),
                f7Tab(
                    title = "Tab 3",
                    tabName = "Tab3",
                    icon = f7Icon("cloud_upload"),
                    active = FALSE,
                    f7Shadow(
                        intensity = 10,
                        hover = TRUE,
                        f7Card(
                            title = "Card header",
                            f7SmartSelect(
                                inputId = "variable",
                                label = "Variables to show:",
                                c("Cylinders" = "cyl",
                                  "Transmission" = "am",
                                  "Gears" = "gear"),
                                multiple = TRUE,
                                selected = "cyl"
                            ),
                            tableOutput("data")
                        )
                    )
                )
            )
        )
    ),
    server = function(input, output) {
        output$distPlot <- renderPlot({
            dist <- rnorm(input$obs1)
            hist(dist)
        })
        
        output$distPlot2 <- renderPlot({
            dist <- switch(
                input$obs2,
                norm = rnorm,
                unif = runif,
                lnorm = rlnorm,
                exp = rexp,
                rnorm
            )
            
            hist(dist(500))
        })
        
        output$data <- renderTable({
            mtcars[, c("mpg", input$variable), drop = FALSE]
        }, rownames = TRUE)
    }
)

usingdatascience avatar Sep 04 '22 16:09 usingdatascience

Where did you get this code from? I just realised that there is a typo uiOutput("distPlot2") should be plotOutput("distPlot2"). I am troubled because the package demo is located here: https://github.com/RinteRface/shinyMobile/blob/master/inst/examples/standalone_tabs/app.R and has the right function.

DivadNojnarg avatar Jan 17 '24 12:01 DivadNojnarg